Created
February 25, 2016 09:45
-
-
Save samuelleach/ebd15d4ac53e34ea7b49 to your computer and use it in GitHub Desktop.
UK postcode regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UK Postcode Regexes: | |
- Assumes upper case letters. | |
- Assumes there is zero or one space between outcode and incode | |
Postcode | |
(?:(?:[A-PR-UWYZ][0-9]{1,2}|[A-PR-UWYZ][A-HK-Y][0-9]{1,2}|[A-PR-UWYZ][0-9][A-HJKSTUW]|[A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRV-Y]) ?[0-9][ABD-HJLNP-UW-Z]{2}|GIR 0AA) | |
Outcode | |
([A-PR-UWYZ][0-9]{1,2}|[A-PR-UWYZ][A-HK-Y][0-9]{1,2}|[A-PR-UWYZ][0-9][A-HJKSTUW]|[A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRV-Y])(?= ?[0-9][ABD-HJLNP-UW-Z]{2}|GIR 0AA) | |
Incode | |
(?![A-PR-UWYZ][0-9]{1,2}|[A-PR-UWYZ][A-HK-Y][0-9]{1,2}|[A-PR-UWYZ][0-9][A-HJKSTUW]|[A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRV-Y] ?)([0-9][ABD-HJLNP-UW-Z]{2}|GIR 0AA) | |
References | |
Useful input from http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment