Regular Expression match all \p{L} but not \p{Alpha}

断了今生、忘了曾经 提交于 2019-12-08 18:46:25

问题


How can I match all \p{L} but not \p{Alpha} in a regular expression? Is it possible to implement a logical AND in Java's Regexp? If the answer is yes, how can that be achieved?


回答1:


Yes, by using a negated character class:

[^\P{L}\p{Alpha}]

[^\P{L}] matches the same as \p{L}, but the negated character class makes it possible to subtract characters/properties from that set of characters.




回答2:


It is possible, but it is Java specific:

[\p{L}&&[^\p{Alpha}]]

(quote as appropriate in a Java string etc)



来源:https://stackoverflow.com/questions/21928277/regular-expression-match-all-pl-but-not-palpha

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