Compliance with Java regex pattern (registration of Irish cars)

Sorry if this is a stupid question, but it got me thinking for the last 5 days.

I am trying to create a regex pattern to match the example of registering an Irish car < 12-W-1234 So far this is what I have:

import java.util.ArrayList;
import java.util.List;

public class ValidateDemo {
    public static void main(String[] args) {
        List<String> input = new ArrayList<String>();
        input.add("12-WW-1");
        input.add("12-W-223");
        input.add("02-WX-431");
        input.add("98-zd-4134");
        input.add("99-c-7465");


        for (String car : input) {
            if (car.matches("^(\\d{2}-?\\w*([KK|kk|ww|WW|c|C|ce|CE|cn|CN|cw|CW|d|D|dl|DL|g|G|ke|KE|ky|KY|l|L|ld|LD|lh|LH|lk|LK|lm|LM|ls|LS|mh|MH|mn|MN|mo|MO|oy|OY|so|SO|rn|RN|tn|TN|ts|TS|w|W|wd|WD|wh|WH|wx|WX])-?\\d{1,4})$")) {
                System.out.println("Car Template " + car);
            }
        }
    }
}

My problems arise when he checks the registers, which will have a single letter in what is in my template. Eg '12-ZD-1234'. If ZDit is not a valid county identifier, but since it is Dvalid, it allows you to display it.

Any help would be great.

-, this .

, .

, , , .

+5
3

\\w*, , ([...]). (|), :

^(\\d{2}-?(KK|kk|ww|WW|c|C|ce|CE|cn|CN|cw|CW|d|D|dl|DL|g|G|ke|KE|ky|KY|l|L|ld|LD|lh|LH|lk|LK|lm|LM|ls|LS|mh|MH|mn|MN|mo|MO|oy|OY|so|SO|rn|RN|tn|TN|ts|TS|w|W|wd|WD|wh|WH|wx|WX)-?\\d{1,4})$

, , :

  • [abc] , a, b, c.
  • [aabbcc] [abc] ( ).
  • [|] , .. .
  • [KK|kk|ww|WW|c|C|ce|CE ... ] [K|wWcCeE ... ], , , .

(|), , , .

+5

:

^[0-9]{2}-?(?>c[enw]?|C[ENW]?|dl?|DL?|g|G|k[eky]|K[EKY]|l[dhkms]?|L[DHKMS]?|m[hno]|M[HNO]|oy|OY|rn|RN|so|SO|t[ns]|T[NS]|w[dhx]?|W[DHX]?)-?[0-9]{1,4}$

:

^(?i)[0-9]{2}-?(?>c[enw]?|dl?|g|k[eky]|l[dhkms]?|m[hno]oy|rn|so|t[ns]|w[dhx]?)-?[0-9]{1,4}$

, (^ $) , .

2: , .

+1

Irish license plates can also begin with three digits, from 2013 they are now (year) (1 | 2) - (county) - (number), so the regular expression can be simple (\ d + -? \ W {2} -? \ d +)

enter image description here

However, the best form of verification is to use the vehicle registration API, such as http://ie.carregistrationapi.com/ , as this will determine if the vehicle is registered, and not just in the correct format.

0
source

All Articles