0

我正在尝试解析一个字符串,但我是模式匹配的新手。这是我的代码:

str = "One[0:0,0,0,0,0,0,0,0,0,0,0,0:1][0:1,0,1,0,0,0,1,1,1,0,0,0:0.5]/Two[0:0,0,0,0,0,0,0,0,0,0,0,0:1.5]/"

for i in string.gmatch(str, "[%a%s]*[%[%]%d:,]*/") do
print("sequence: "..i)
end

它应该打印 One[0:0,0,0,0,0,0,0,0,0,0,0,0:1][0:1,0,1,0,0,0,1, 1,1,0,0,0:0.5] 两个[0:0,0,0,0,0,0,0,0,0,0,0,0:1.5]

但它会打印

序列:5]/序列:5]/

4

1 回答 1

1

您的模式中缺少."[%a%s]*[%[%]%d:%.,]*/",因此0.51.5无法匹配。它只匹配最后一个数字。

于 2013-01-27T05:05:53.817 回答