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

Writing a regular expression for multiple outcomes

I need help writing a regular expressions which has multiple outcomes. FYI, each letter can be A-Z and each number can be 0-9. I’m searching for a reference number which can have a mix of different character and digit lengths, as well as, different delimiters.

Here is the structure:
    
{2 or 3 letters}  {. or /} {2 or 3 letters}  {. or /} {7 or 8 digits} {. or / or -}  {1, 2 or 8 digits}

     ABC             /            ABC            /       0000000             -                01 


Some Examples:

ABC/ABC/0000000-00
ABC/ABC/00000000/0
ABC/AB/00000000.00
AB/AB/0000000-00
ABC.ABC.0000000-00
AB.AB.0000000-00

Is it possible to write this within one RegEx?

Any help would be much appreciated! Thanks

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 :

The trick is use the | inside parenthesis to make and OR:

[A-Z]{2,3}(\/|\.)[A-Z]{2,3}(\/|\.)[0-9]{7,8}(\-|\/|\.)[0-9]+

https://regex101.com/r/fo5dLZ/1

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