开发者

Java regex pattern

开发者 https://www.devze.com 2023-04-10 22:11 出处:网络
Is there any way of excluding this characters: - \\ _ to this pattern? I need especifically this pattern and no other

Is there any way of excluding this characters: - \ _ to this pattern? I need especifically this pattern and no other

Pattern pattern = 开发者_JAVA百科Pattern.compile("[\\p{P}\\p{Z}]");


Use character class subtraction:

Pattern.compile("[\\p{P}\\p{Z}&&[^-_\\\\]]");


Generally to exclude a character you prepend it with ^. for example to match any number of characters that do not containt character 'a' you write:

[^a]*
0

精彩评论

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