0

I am looking for official/reliable regexps to extract sector/district/areas from a UK postcode. I have found a few online but I am not sure how good they are, and I have not a way to test them properly. Do you know any of those regex that can be considered valid?

1 Answer 1

2
/^(((([A-Z][A-Z]{0,1})[0-9][A-Z0-9]{0,1}) {0,}[0-9])[A-Z]{2})$/

This matches, in order:

  • Unit Postcode
  • Postcode Sector
  • Postcode District
  • Postcode Area

I have a page on my website which addresses postcode format and using regular expressions to parse a post code into it's constituent parts.

1
  • I am using exactly the same regexp at the moment, that I got from another website
    – Randomize
    Sep 27, 2018 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.