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

Matching specific strings in regex pattern

I have multiple records and I want to match specific strings and at the same time unmatched specific strings. I came up with one pattern but it matches all. Anyone can revise the pattern please?

Pattern: /PF\s*(?:XAP|FNI)?\s*O\/\s*(?:RG|VO|HS).*\s*\+?(?!HSAC|VOG)/gm

Here are the records-

Here are the records should be matched:
PFO/RGETK
PFO/RGETK+/RGETK
PFO/VOG+/RGETK
PFO/VOG+/VOG
PFO/RGETK+/VOG
PFXAPO/RGETK
PFXAPO/RGETK+/RGETK
PFXAPO/VOG+/RGETK
PFXAPO/VOG+/VOG
PFXAPO/RGETK+/VOG
PFFNIO/RGETK
PFFNIO/RGETK+/RGETK
PFFNIO/VOG+/RGETK
PFFNIO/VOG+/VOG
PFFNIO/RGETK+/VOG
PF O/RGETK+/HSAC
PF O/HSAC+/RGETK
PF O/RG+/RGETK
PF O/RG+/HSAC

Here are the records should NOT be matched:
PFO/VOG
PFO/VOG+/HSAC
PFO/HSAC+/HSAC
PFXAPO/VOG
PFXAPO/VOG+/HSAC
PFXAPO/HSAC+/HSAC
PFFNIO/VOG
PFFNIO/VOG+/HSAC
PFFNIO/HSAC+/HSAC

>Solution :

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

You can use

^PF\s*(?:(?:XAP|FNI)\s*)?O\/(?!\s*(?:VOG\+?(?:\/HSAC)?|HSAC\+?\/HSAC)$)\s*(?:RG|VO|HS)[A-Z]*\+?(?:\/[A-Z]+)?$

See the regex demo.

Details:

  • ^ – start of string
  • PFPF
  • \s* – zero or more whitespaces
  • (?:(?:XAP|FNI)\s*)? – an optional sequence of XAP or FNI and then zero or more whitespaces
  • O\/O/
  • (?!\s*(?:VOG\+?(?:\/HSAC)?|HSAC\+?\/HSAC)$)
  • \s* – zero or more whitespaces
  • (?:RG|VO|HS)RG, VO or HS
  • [A-Z]* – zero or more uppercase ASCII letters
  • \+? – an optional + char
  • (?:\/[A-Z]+)? – an optional sequence of / and one or more ASCII uppercase letters
  • $ – end of string.
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