title: Grep character sequence
body: <p>I need to match character sequences of the form <code>ABCD12345</code> and others of the form <code>ABCD54321.aaa</code>.</p>
  
  <p>I have written code to check for both forms, but it only works correctly for input sequence <code>ABCD12345</code> because <code>ABCD54321.aaa</code> is matched by both RegEx's (the one for <code>ABCD54321.aaa</code> and the one for <code>ABCD54321</code>). </p>
  
  <p>How do I modify my regular expression(s) so that only one of them matches when the input is <code>ABCD54321.aaa</code>?</p>
  
  <p>Here is a snippet of my java code which shows the patterns that I am using to match character sequences:</p>
  
  <pre><code>String[] patternValues = new String[] { "[Aa.][Bb][Cc][Dd]\\d+\\.+[a-zA-Z]{3}","[Aa.][Bb][Cc][Dd]\\d+"} ;
  for(int i = 0 ; i &lt;= (patternValues.length - 1) ; i++) {
      Pattern regexp = Pattern.compile(patternValues[i]);
      ..... 
  }
  </code></pre>