[英]How to find a character in a string which is not matching the regex pattern
有一个正则表达式,我需要找到与正则表达式不匹配的字符。 然后将字符替换为“”。在JAVA中如何实现?
Pattern : ^((?![\|\=\;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])+$
Sample Text: HAIRCUT $42 PER PERSON
Required output: HAIRCUT 42 PER PERSON
否定您已经拥有的。
查找(?!(?![|=;])[\\p{L}\\p{N}\\p{M}\\p{P}\\p{Zs}])[\\S\\s]
nothing
https://regex101.com/r/Sn3DuL/1
(?!
(?! [|=;] )
[\p{L}\p{N}\p{M}\p{P}\p{Zs}]
)
[\S\s]
您可以替换与正则表达式匹配的字符。
String myString = "HAIRCUT $42 PER PERSON";
myString = myString.replaceAll("^((?![\|\=\;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])+$", "");
结果:
HAIRCUT 42 PER PERSON
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.