Victor
Victor

Reputation: 1271

Regex For Letters/Numbers combination

Trying to come up with a regex to capture groups like AB1234 or BA2321. Essentially need to capture anything that starts with AB or BA and followed by 4 digits.

Currently, I have something like this, but that seems to not take numbers into account

(AB|BA)\d{4}

Upvotes: 0

Views: 46

Answers (2)

Thomas Ayoub
Thomas Ayoub

Reputation: 29431

I would use this:

^(AB|BA)\d{4}$

Upvotes: 0

Toto
Toto

Reputation: 91373

May be you want:

\b((?:AB|BA)\d{4})\b

Letters + digits will be in group 1

Upvotes: 1

Related Questions