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

Regex Match Phrase with Different Symbols

I have here a phrase AAC Barcode Description that regex should match.

The problem is sometimes I have underscore, symbols etc…
like

  • AAC Barcode + Descriptions
  • AAC Barcode + Description
  • AAC Barcode & Descriptions
  • AAC Barcode and Description

REGEX

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

\b\w*AAC Barcode Description\w*\b

>Solution :

You can use

\w*AAC Barcode(?:\s+and\s+|\W+)Description\w*

See the regex demo. Note that word boundaries are redundant in this case when used with \w*s. If you want to match this string is a whole word, you need to remove \w*s and keep \bs:

\bAAC Barcode(?:\s+and\s+|\W+)Description\b

Details:

  • \w* – zero or more word chars
  • AAC Barcode – a fixed string
  • (?:\s+and\s+|\W+) – a non-capturing group matching either and enclosed with one or more whitespaces or one or more non-word chars
  • Description – a fixed string
  • \w* – zero or more word chars
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