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

2019-06-17 06:54发布

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?

2条回答
何必那么认真
2楼-- · 2019-06-17 07:06

It is possible, but it is Java specific:

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

(quote as appropriate in a Java string etc)

查看更多
We Are One
3楼-- · 2019-06-17 07:22

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.

查看更多
登录 后发表回答