I’m looking for the perfect regular expression for validation a german car license
the number has too look like this:
1-3 Letters
a MINUS (i know the minus is now out of date, but the customer want it that way)
1-2 Letters
a SPACE
1-4 numbers
m a 12 –> wrong
abc a 12 –> wrong
m-a 12 –> correct
abc-abc 12 –> wrong
abc-ab-12 –> wrong
abc-ab 1234 –> correct
ab-ab 1234 –> correct
abc-ab 12345 wrong
I was using ([a-z]+)[-]?([a-z]*)\s*(\d+) (so without counting numbers) but it was going the wrong way.
Try the following:
This roughly breaks down into:
^Start of string[a-zA-Z]{1,3}A letter between 1 and 3 times (inclusive)-A hyphen[a-zA-Z]{1,2}A letter between 1 and 2 times (inclusive)A space character\d{1,4}A digit (0 – 9) between 1 and 4 times (inclusive)$The end of the string