title: Regex to get area and district codes from UK postcodes
body: <p>Basically, I need a regex that would match first sequence of letters in UK postcode (easy) and another regex which would match the following number (not so easy). </p>
  
  <p>Examples of possible combinations and matches:</p>
  
  <pre><code>AA9A 9AA    regex1: AA    regex2: 9
  A9A 9AA     regex1: A     regex2: 9
  A9 9AA      regex1: A     regex2: 9
  A99 9AA     regex1: A     regex2: 99
  AA9 9AA     regex1: AA    regex2: 9
  AA99 9AA    regex1: AA    regex2: 99
  </code></pre>
  
  <p>Spaces in poscodes are only there for clarity, they might or might not be there, therefor must be disregarded.</p>
  
  <p>I could use some help with these two regular expressions, especially regex2 (matching the number). By the way, I'm gonna be running this in MySQL 5.6</p>
  
  <p><strong>UPDATE:</strong> Just to note: last 3 characters will always be ignored no matter what, that's the only pattern that always applies - it should be visible from my examples.</p>
  
  <p><strong>UPDATE2:</strong> Sorry if I wasn't clear enough before - I don't need to validate the post codes, I need to extract area and district codes.</p>
  
  <p><strong>UPDATE3:</strong> Just to emphasize again: white space must be disregarded, it could be <code>AA99 9AA</code> or <code>AA999AA</code> - in both cases the regex2 (extract number) should be <code>99</code> </p>
  
  <p><strong>UPDATE4:</strong> Thanks for all your answers, unfortunately I just found out that MySQL can't extract regex matches. Way to go, MySQL, proving to be useless yet again.</p>