Equivalent pattern to “[\0-\x7F\xC2-\xF4][\x80-\xBF]*” in Lua 5.1

前端 未结 2 2022
暖寄归人
暖寄归人 2020-12-21 06:06

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-\\         


        
2条回答
  •  醉酒成梦
    2020-12-21 06:29

    See the Lua 5.1 manual on patterns.

    A pattern cannot contain embedded zeros. Use %z instead.
    

    In Lua 5.2, this was changed so that you could use \0 instead, but not so for 5.1. Simply add %z to the first set and change the first range to \1-\127.

提交回复
热议问题