Henry
Henry

Reputation: 159

Lua string patterns

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]/

Upvotes: 0

Views: 127

Answers (1)

Paul Kulchenko
Paul Kulchenko

Reputation: 26794

You are missing . in your pattern: "[%a%s]*[%[%]%d:%.,]*/", so 0.5 or 1.5 can't match. It just matches the last digit.

Upvotes: 1

Related Questions