Reputation: 1338
I'm trying to match number plates in a database using REGEX so I can set them a type, so I don't have to use REGEX in any future queries.
I've got two expressions that match dateless / irish plates. I need to separate irish plates from dateless plates.
Irish plates must include the letter I or Z, dateless plates cannot include I or Z.
These are the two expressions that match both dateless and irish.
REGEXP '^[A-Z]{1,3}[0-9]{1,4}$'
REGEXP '^[0-9]{1,4}[A-Z]{1,3}$'
The problem I have is excluding the I-Z, I can do [A-HJ-Y], but this will result in crossovers.
How can I modify the expressions above to require I and Z, and then another set of expressions to exclude I and Z.
Many Thanks
Upvotes: 0
Views: 93
Reputation: 125925
Irish plates are either:
^([IZ][A-Z]{0,2}|[A-Z]([IZ][A-Z]?|[A-Z][IZ]))[0-9]{1,4}$
^[0-9]{1,4}([IZ][A-Z]{0,2}|[A-Z]([IZ][A-Z]?|[A-Z][IZ]))$
If you're prepared to tolerate up to 5 letters, these can be simplified to:
^[A-Z]{0,2}[IZ][A-Z]{0,2}[0-9]{1,4}$
^[0-9]{1,4}[A-Z]{0,2}[IZ][A-Z]{0,2}$
Dateless plates are either:
^[A-HJ-Y]{1,3}[0-9]{1,4}$
^[0-9]{1,4}[A-HJ-Y]{1,3}$
Upvotes: 1