splitStr模块可开关正则(默认不用)

This commit is contained in:
MrZ626
2021-04-12 02:08:54 +08:00
parent 7d67288766
commit 14adcff9dc

View File

@@ -1,11 +1,19 @@
local find,sub=string.find,string.sub
return function(s,sep)
return function(s,sep,regex)
local L={}
local p1,p2=1--start,target
while p1<=#s do
p2=find(s,sep,p1)or #s+1
L[#L+1]=sub(s,p1,p2-1)
p1=p2+#sep
if regex then
while p1<=#s do
p2=find(s,sep,p1)or #s+1
L[#L+1]=sub(s,p1,p2-1)
p1=p2+#sep
end
else
while p1<=#s do
p2=find(s,sep,p1,true)or #s+1
L[#L+1]=sub(s,p1,p2-1)
p1=p2+#sep
end
end
return L
end