title: ruby regex .scan
body: <p>I'm using Ruby's scan() method to find text in a particular format. I then output it into a string separated by commas. The text I'm trying to find would look like this: </p>
  
  <p><code>AB_ABCD_123456</code></p>
  
  <p>Here's the what I've come up with so far to find the above. It works fine:</p>
  
  <pre><code>text.scan(/.._...._[0-9][0-9][0-9][0-9][0-9][0-9]/)
  puts text.uniq.sort.join(', ')
  </code></pre>
  
  <p>Now I need a regex that will find the above with or without a two-letter country designation at the end. For example, I would like to be able to find all three of the below:</p>
  
  <p><code>AB_ABCD_123456</code><br>
  <code>AB_ABCD_123456UK</code><br>
  <code>AB_ABCD_123456DE</code></p>
  
  <p>I know I could use two or three different scans to achieve my result, but I'm wondering if there's a way to get all three with one regex.</p>