Wanna write a RegEx to validate a driving license.
if it doesn’t start with (US, CA, CN) then it has to be followed with XX and after that with any number of Alpha numeric letters.
So for example if the driving license starts with GB then it has to be followed with XX GBXX12345363 However if it starts with US then we don’t care what comes after it. USLA039247230
Remember not everyone is familiar with that driving license notation, I’m assuming that what follows is the precise specification (you should really try to be very precise when asking for a regex else you’ll get things you don’t want):
If those first two letters are none of US, CA or CN, then the next two letters have to be X, the rest after that has to be alphanumeric and of unspecified length
((US|CA|CN)[A-Za-z0-9]+|(?<!(US|CA|CN))[A-Z]{2}XX[A-Za-z0-9]+)
First part:
Second part:
And it matches either the first part or the second one