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
>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