Lua的libpcre实现不支持'\d'是可能的吗?

我发现 \d 不能被识别为 [0-9]。请看下面的控制台输出:

> require "rex_pcre"
> return rex_pcre.new("[0-9]+"):exec("1234")
1       4       table: 0x2141ce0
> return rex_pcre.new("\d+"):exec("1234")
nil

我有什么遗漏或者错了吗?

更新

正如 Kevin Ballard 正确回答的那样,使用字符串转义可以解决问题!例如:

> return rex_pcre.new("\\d+"):exec("1234")
1       4       table: 0x21427f0
> return rex_pcre.new([[\d+]]):exec("1234")
1       4       table: 0x2142ee0

谢谢 Kevin!

原文链接 https://stackoverflow.com/questions/8380918

点赞
stackoverflow用户582
stackoverflow用户582

我想这是因为Lua将 \d 解释为字符串转义。 可以尝试使用 "\\d+"[[\d+]]。 有关语法的解释在这里

2011-12-05 04:10:44