Regular expression \p{L} and \p{N}

后端 未结 2 582
半阙折子戏
半阙折子戏 2020-11-28 04:11

I am new to regular expressions and have been given the following regular expression:

(\\p{L}|\\p{N}|_|-|\\.)*

I know what * means and | me

相关标签:
2条回答
  • 2020-11-28 04:28

    These are Unicode property shortcuts (\p{L} for Unicode letters, \p{N} for Unicode digits). They are supported by .NET, Perl, Java, PCRE, XML, XPath, JGSoft, Ruby (1.9 and higher) and PHP (since 5.1.0)

    At any rate, that's a very strange regex. You should not be using alternation when a character class would suffice:

    [\p{L}\p{N}_.-]*
    
    0 讨论(0)
  • 2020-11-28 04:32

    \p{L} matches a single code point in the category "letter".
    \p{N} matches any kind of numeric character in any script.

    Source: regular-expressions.info

    If you're going to work with regular expressions a lot, I'd suggest bookmarking that site, it's very useful.

    0 讨论(0)
提交回复
热议问题