我有以下数据集:
Word-1-random
Word-2-random
Word-3-random
Word-4-random
upto
Word-19-random
Other-Word-1-random
Other-Word-2-random
Other-Word-3-random
Other-Word-4-random
upto
Other-Word-19-random
现在我想对一组日期进行匹配,数字1-5、6-10、11-15等。我以为是以下内容:
match("^Word%-d[1-5]%-",string)
match("%-Word%-d[1-5]%-",string)
根据您的示例,这个想法可能是这样的:
<script src="https://github.com/fengari-lua/fengari-web/releases/download/v0.1.4/fengari-web.js"></script>
<script type="application/lua">
local text = [[
Word-1-random
Word-2-random
Word-3-random
Word-4-random
upto
Word-19-random
Other-Word-1-random
Other-Word-2-random
Other-Word-3-random
Other-Word-4-random
Other-Word-5-random
Other-Word-6-random
Other-Word-7-random
Other-Word-8-random
Other-Word-9-random
Other-Word-10-random
Other-Word-11-random
]]
local s1,s2
local grp,cnt = 0,0
text:gsub('(%S+%-)(%d+)(%-%S+)', function(p1,n,p2)
if s1 ~= p1 or s2 ~= p2 or cnt == 5 then
print('Group'..grp)
s1,s2 = p1,p2
cnt = 0
grp = grp + 1
end
print(p1..n..p2)
cnt = cnt + 1
end)
</script>