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

Capture [a-zA-Z] except for specific sequence of characters ("PT")

I have this capturing subgroup in my regex statement. What I am trying to achieve is to add an exception to the bold/first matching group ([a-zA-Z]{2}) which should not match the specific word "PT". I am using VBScript.RegEx which is said to be similar to Javascript RegEx.

([a-zA-Z]{2}|[a-zA-Z]{1}\d{1}|\d{1}[a-zA-Z]{1})

Refer to the table below for the decision tree.

word match
AA Pass
A1 Pass
1A Pass
PT Fail
pt Fail
pT Fail

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

>Solution :

You can use a negative lookahead conditional:

(?![Pp][Tt])\w{2}

The (?! means the next two characters should not match the value inside the parenthesis, in this case [Pp][Tt].

Try it on Regex101

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