Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How remove a specific substring between parenthesis using Regular Expressions?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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 )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading