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

后端 未结 2 770
無奈伤痛
無奈伤痛 2021-02-07 16:56

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

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 17:01

    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.

提交回复
热议问题