String pattern anchor (^) treated as regular character

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?

From the wiki: “For this function, a ‘^’ at the start of pattern does not work as an anchor, as this would prevent the iteration.” You should be able to use string.match(string, pattern) as a substitute.

local colourText = '255, 192, 13'
local f1, f2, f3 = colourText:match('^%s*(%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*$')
print(f1, f2, f3)

Ah cheers! I figured I had probably missed something like that. I’ll use match instead.