I’ve encountered an issue with string patterns today.
Weirdly, the beginning anchor (^) didn’t work. It was treated as a regular character instead of a special character. This has never happened before when I’ve used patterns in the past, but I just thought I’d check before posting it as a bug report. Here’s a simplified demo to show the issue:
local pattern = '^%d'
local test1 = '12'
local test2 = 'a34'
local test3 = '^56'
for s in test1:gmatch( pattern ) do
print( s ) -- prints nothing, should print 1
end
for s in test2:gmatch( pattern ) do
print( s ) -- prints nothing, correct
end
for s in test3:gmatch( pattern ) do
print( s ) -- prints ^5, should just print 5
end
My actual pattern and code
local colourText = '255, 192, 13'
for f1, f2, f3 in colourText:gmatch( '^%s*(%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*$' ) do
print( f1, f2, f3 )
end
-- Outputs nothing, unless I remove ^ from the pattern.
Is anyone else experiencing this? Is this just the latest version (in which case it’s a bug)? Or did I miss something?