splitStr模块可开关正则(默认不用)
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
local find,sub=string.find,string.sub
|
local find,sub=string.find,string.sub
|
||||||
return function(s,sep)
|
return function(s,sep,regex)
|
||||||
local L={}
|
local L={}
|
||||||
local p1,p2=1--start,target
|
local p1,p2=1--start,target
|
||||||
while p1<=#s do
|
if regex then
|
||||||
p2=find(s,sep,p1)or #s+1
|
while p1<=#s do
|
||||||
L[#L+1]=sub(s,p1,p2-1)
|
p2=find(s,sep,p1)or #s+1
|
||||||
p1=p2+#sep
|
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
|
end
|
||||||
return L
|
return L
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user