title: Java regex pattern matching (Irish car registration)
body: <p>Sorry if this a dumb question but it's been driving me mental for the past 5 days.</p>
  
  <p>I'm trying to make a <strong>regex pattern</strong> to match the <strong>Irish</strong> car registration example '<code>12-W-1234</code>'
  So far this is what I have:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  public class ValidateDemo {
      public static void main(String[] args) {
          List&lt;String&gt; input = new ArrayList&lt;String&gt;();
          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);
              }
          }
      }
  }
  </code></pre>
  
  <p>My problems are coming up when it is checking regs that would have a <strong>single letter</strong> in the that is in my pattern. Eg <code>'12-ZD-1234'</code>.
  Where <code>ZD</code> isn't a valid county ID but since <code>D</code> is valid it allows it to be displayed.</p>
  
  <p>Any help would be great.</p>
  
  <p>I've already done research on a few websites including <a href="http://www.javacodegeeks.com/2012/11/java-regular-expression-tutorial-with-examples.html" rel="nofollow">this</a> and <a href="http://www.vogella.com/articles/JavaRegularExpressions/article.html" rel="nofollow">this</a>.</p>
  
  <p>These websites helped, but I'm still having my problems.</p>
  
  <p>By the by, I'am going to change the pattern to change all inputs into
  uppercase to reduce the size of my code.
  Thanks for the help</p>