【问题标题】:Is it possible that Lua's libpcre implementation does not support '\d'?Lua的libpcre实现是否可能不支持'\d'?
【发布时间】:2011-12-05 04:08:07
【问题描述】:

我发现\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

我错过了什么还是什么?

更新

正如凯文巴拉德正确回答的那样,字符串转义有效!例如

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

谢谢凯文

【问题讨论】:

  • 我刚做了,但是花了一些时间,因为在问题发布后 10 或 15 分钟之前不要让接受答案。

标签: regex lua pcre


【解决方案1】:

我想这是因为 \d 被 Lua 解释为字符串转义。尝试改用"\\d+"[[\d+]]。语法是explained here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-23
    • 2022-08-17
    • 2022-10-14
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多