When answering this question, I wrote this code to iterate over the UTF-8 byte sequence in a string:
local str = "KORYTNAČKA"
for c in str:gmatch("[\0-\x7F\xC2-\xF4][\x80-\xBF]*") do
print(c)
end
It works in Lua 5.2, but in Lua 5.1, it reports an error:
malformed pattern (missing ']')
I recall in Lua 5.1, the string literal \xhh
is not supported, so I modified it to:
local str = "KORYTNAČKA"
for c in str:gmatch("[\0-\127\194-\244][\128-\191]*") do
print(c)
end
But the error stays the same, how to fix it?
"[%z\1-\127\194-\244][\128-\191]*"
works, using"%z"
as an individual character in the set. – Amaral