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

自古美人都是妖i 提交于 2019-11-26 09:06:58

问题


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

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

I know what * means and | means \"or\" and that \\ escapes.

But what I don\'t know what \\p{L} and \\p{N} means. I have searched Google for it, without result...

Can someone help me?


回答1:


\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.




回答2:


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}_.-]*


来源:https://stackoverflow.com/questions/14891129/regular-expression-pl-and-pn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!