开发者

Is there a way to use \p{Punct} in a regex(java), but without the "(",")" characters?

开发者 https://www.devze.com 2023-03-12 00:46 出处:网络
Is there a way to use \\p{Punct}开发者_Go百科 in a regex in java, but without the two characters ( and ) ? You should be able to use:

Is there a way to use \p{Punct}开发者_Go百科 in a regex in java, but without the two characters ( and ) ?


You should be able to use:

[\p{Punct}&&[^()]]

What this is saying is:

The punct character class except for ( and ).

The ^ character specifies a negative character class. The && is an intersection between the punct class and the custom class for the parenthesis.

Have a look at the Pattern Javadocs for more info.


This should work:

[\p{Punct}&&[^()]]

&& is the intersection operator for character classes, so the intersection of \p{Punct} and [^()] is what you're after. See Character Classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消