I’m trying to parse a string but I’m new to pattern matching.
Here’s my code:
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
It should print
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]
but instead it prints
sequence: 5]/
sequence: 5]/
You are missing
.in your pattern:"[%a%s]*[%[%]%d:%.,]*/", so0.5or1.5can’t match. It just matches the last digit.