I need to build a regular expression, with the following details. The regular expression needs to match in the following chars structure:
OT-001-16
OT
: They may be uppercase or lowercase, but I only need to match if it is O
followed by T
, not T
and followed by O
.-
Followed by this character.001
Followed by 3 or more numbers.-
Followed by this character.16
And finally followed by exact 2 numbers.This is what I've tried:
/([OT|ot]{2})-(\d{3,})-(\d{2})/g
This regular expression works fine, except if I write TO-0052-54
, the problem is with the OT
chars, I need to match only if a O
is followed by T
.
Thanks and any question post on comments.
by using [OT|ot]{2}
you are actually comparing a string that has char O or o and T or t of length 2. It is like using something like this.
[ABCD]{2}
: where it matches all the possibles combinations of characters.
To solve this, use (OT|ot)
which matches between this particular pattern OT or ot.