title: Regular Expression Help - Lookahead
body: <p>I'm trying to validate some input text (this is part of a larger regex)  and basically I have a list of values, Replaced with arbitrary characters in this example and I want to match that they have the correct convention.. </p>
  
  <p>IE I want to match AAA001 but not AAA00 and match ZZ00.</p>
  
  <p>I want the AAA and ZZ's to be returned as the same group, IE group 1, but the digits excluded..</p>
  
  <p>here's where I'm up to:</p>
  
  <pre><code>^((AAA|BBC|CCC)(?=\d{3})|(ZZ|XX|YY)(?=\d{2}))$
  </code></pre>
  
  <p><img src="https://www.debuggex.com/i/YdaulGpdbyK738T6.png" alt="Regular expression visualization"></p>
  
  <p><a href="https://www.debuggex.com/r/YdaulGpdbyK738T6" rel="nofollow">Debuggex Demo</a></p>
  
  <p>Where am I going wrong with the concept of lookahead's? I've tried reading but to no avail.</p>
  
  <p>Thanks</p>
  
  <p>Edit:</p>
  
  <p>so this is an example of the full 'obfuscated' regex.. </p>
  
  <pre><code>^(?:OOO)(ABC|DEF)(RR|AA|DD|EE)((?:AAA|BBC|CCC)(?=\d{3})|(?:ZZ|XX|YY)(?=\d{2}))$
  </code></pre>
  
  <p><img src="https://www.debuggex.com/i/SZkxpm1wslHhcHgc.png" alt="Regular expression visualization"></p>
  
  <p><a href="https://www.debuggex.com/r/SZkxpm1wslHhcHgc" rel="nofollow">Debuggex Demo</a></p>
  
  <p>so in my latest example above.. I would want group 3 to return AAA|BBB|CCC but not contain the digits.. if possible then group 4 could return the sequence number but not important, they can be discarded.. </p>
  
  <p>David</p>