Reputation: 57
Require some help with building Regex formula to validate input string.
Below is my formula that I've come with so far but some parts does not work as per required.
Requirements:-
Acceptable Input String
Samples:
-'11910281 --> Not Match'
-'9U910281 --> Match'
-'BC189201 --> Match'
-'BC189201.01 --> Match'
-'BC189201_01 --> Match'
-'BC189201-01 --> Match'
OR String as below
MTMBX|MTTBX|MTRBX|MTRBX|MTREJ
Not Acceptable Input String With Prefix
GMSS|GTSS|GRRT|REJS
Upvotes: 0
Views: 46
Reputation: 163277
You could use
^(?!GMSS|GTSS|GRRT|REJS)(?:(?=[^A-Z\s]*[A-Z])[A-Z0-9._-]{8,16}|MTMBX|MTTBX|MTRBX|MTRBX|MTREJ)$
The pattern matches:
^
Start of string(?!GMSS|GTSS|GRRT|REJS)
Negative lookahead, assert not any of the alternatives(?:
Non capture group
(?=[^A-Z\s]*[A-Z])
Positive lookahead, assert at least a single char A-Z[A-Z0-9._-]{8,16}
Match any of the listed 8-16 times|
OrMTMBX|MTTBX|MTRBX|MTRBX|MTREJ
Match any of the allowed alternatives)
Close non capture group$
End of stringUpvotes: 1