【问题标题】:Allowed named subpattern characters允许的命名子模式字符
【发布时间】:2011-08-14 02:03:46
【问题描述】:

命名子模式中允许哪些字符,是否可以在命名子模式中转义?

(?<name>\w+)

我想使用这个例子 http://www.php.net/manual/en/function.preg-match.php#example-3946 并希望使用“hello-name”而不是“name”。

【问题讨论】:

    标签: php regex escaping preg-match character


    【解决方案1】:

    PCRE 仅允许子模式名称使用​​字母数字字符和下划线:
    http://regexkit.sourceforge.net/Documentation/pcre/pcrepattern.html#SEC14

    【讨论】:

    • 什么是有效名称的正则表达式?
    • 一如既往地假设[a-z]\w*是最安全的。
    猜你喜欢
    • 2021-10-14
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2018-03-20
    • 2019-10-27
    • 2013-10-29
    相关资源
    最近更新 更多