Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何在一组数字上进行字符串匹配?_String_Lua_Match - Fatal编程技术网

String 如何在一组数字上进行字符串匹配?

String 如何在一组数字上进行字符串匹配?,string,lua,match,String,Lua,Match,我有以下数据集: 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

我有以下数据集:

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) 

根据你的例子,这个想法可能是这样的:


本地文本=[[
字随机
字2-随机
单词-3-随机
字4-随机
最多
Word-19-random
换句话说,1-随机
换句话说,2-随机
换句话说,3-随机
换句话说,4-随机
换句话说,5-随机
换句话说,6-随机
换句话说,7-随机
换句话说,8-随机
换句话说,9-随机
换句话说,10-随机
换句话说,11-随机
]]
本地s1、s2
局部grp,cnt=0,0
文本:gsub('(%S+%-)(%d+)(%-%S+),函数(p1,n,p2)
如果s1~=p1或s2~=p2或cnt==5,则
打印('组'…grp)
s1,s2=p1,p2
cnt=0
grp=grp+1
结束
打印(p1..n..p2)
cnt=cnt+1
(完)

match(“Word%-[1-5]-%S+”,string)
Word-1-…
匹配到
Word-5-…
匹配(“Word%-1[1-5]-%S+”,string)
Word-11-…
匹配到
Word-15-…
您是匹配文本字符串
Word
还是将其用作替身?如果您提供了要解析的字符串的真实示例以及希望从中得到什么,这也会有所帮助。另外,string.match的格式应该是
string.match(word,pattern)
(您将其命名为
string.match(pattern,word)
)。