unicode - 如何在Lua中搜索Unicode空白字符

标签 unicode lua whitespace lua-patterns

我要搜索Unicode whitespace chars使用Lua在文件中。对于 ASCII,我们可以使用 %s 但我没有找到任何可以在 Unicode 文件中搜索空白字符的内容。

最佳答案

Lua 5.2 及更早版本对 Unicode 的支持很少。

(即将推出)Lua 5.3提供了一个基本的UTF-8库。但是,它仍然不知道该字符的含义(例如什么是空白字符)。在使用 utf8.codes 迭代每个代码点后,您需要自己完成该部分。 .

--table to be filled 
local whitespace = {0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0x85, 0xA0, 0x1680, 0x2000, 0x2001}

local str = 'hello\u{2000}world\n'
for _, c in utf8.codes(str) do
    for _, v in ipairs(whitespace) do
        if c == v then
            print 'whitespace found'
        end
    end
end

关于unicode - 如何在Lua中搜索Unicode空白字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23355626/

相关文章:

linux - 如何将带有空格的绝对文件路径传递给 linux shell 脚本?

Java 6 支持的 Unicode 版本

java - 编写没有 BOM 的 UTF-8

c++ - 游戏NPC多 Action lua脚本设计

mysql - 将唯一的选择值分配给唯一的一个变量

python - getch() 返回错误字符

variables - 在lua中使用for循环创建多个变量

html - 与空白 :nowrap

html - dontent div min-height=100% 创建空白