How to find a character in a string which is not matching the regex pattern

suse :

There is a regex and I need to find the character not matching the regex. Then replace the character with "" in. How to achieve this in JAVA?

Pattern : ^((?![\|\=\;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])+$
Sample Text: HAIRCUT $42 PER PERSON
Required output: HAIRCUT 42 PER PERSON
user557597 :

Just negate what you already have.

Find (?!(?![|=;])[\p{L}\p{N}\p{M}\p{P}\p{Zs}])[\S\s]
Replace nothing

https://regex101.com/r/Sn3DuL/1

 (?!
      (?! [|=;] )
      [\p{L}\p{N}\p{M}\p{P}\p{Zs}] 
 )
 [\S\s]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=131959&siteId=1