Home > front end >  How remove a specific substring between parenthesis using Regular Expressions?
How remove a specific substring between parenthesis using Regular Expressions?

Time:01-25

I am learning REGEX and I have the following string:

minchiase (se), minchiase se

My goal is to remove all the se and (se) from the string except the ones that are inside of a word. The final result should be:

minchiase , minchiase

So far I tried this \b(se) but I am only able to identify the last se but not the one between the parenthesis.

Would you be able to suggest a smart and elegant way to achieve this goal using the regular expression?

CodePudding user response:

You may use this regex:

\bse\b|\(se\)

RegEx Demo

RegEx Details:

  • \b: Match word boundary
  • se: Match se
  • \b: Match word boundary
  • |: OR
  • \(: Match opening (
  • se: Match se
  • \): Match closing )
  •  Tags:  
  • Related