I'm actually trying to match some order numbers in a string.
The string could look like this:
SDSFwsfcwqrewrPL0000018604ergerzergdsfa
or
FwsfcwqrewrAT0000018604ergerzergdsfaD
and I need to match the "PL0000018604" or "AT0000018604".
Actually I'm using something like that and it works:
.?(AT[0-9]{10})|(BE[0-9]{10})|(FR[0-9]{10})|(IT[0-9]{10})
But the more order prefixes we get, the longer the expression will be. It is always 2 uppercase chars followed by 10 digits and I want to specify the different uppercase chars.
Is there any shorter version?
Thanks for your help :)
If the prefixes must be specific, there's not much of a way to make the pattern shorter. Though, you can collect all the prefixes at the front of the expression so you only have to have the numeric part once.
for example:
(AT|BE|FR|IT)[0-9]{10}
Depending on how you call it, if you need the whole expression to be captured as a group (versus simply matching, which is what the question asked about), you can add parenthesis around the whole expression. That doesn't change what is matched, but it will change what is returned by whatever function uses the expression.
((AT|BE|FR|IT)[0-9]{10})
And, of course, if you just want the number part to also be captured as a separate group, you can add more parenthesis
((AT|BE|FR|IT)([0-9]{10}))