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

后端 未结 2 1472
旧巷少年郎
旧巷少年郎 2021-02-07 16:44

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

2条回答
  •  终归单人心
    2021-02-07 17:21

    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.

提交回复
热议问题