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
/^(((([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.
-
I am using exactly the same regexp at the moment, that I got from another website Sep 27, 2018 at 10:30