[英]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.