Regular Expressions 101

Community Patterns

1...34567...902

Community Library Entry

1

Regular Expression
Python

r"
^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$
"

Description

Matches more thoroughly than others in the library. Based on http://stackoverflow.com/questions/164979/uk-postcode-regex-comprehensive. Matches: W1A 1AA, WC2H 7LT, SE50EG

Submitted by spookypeanut - 9 years ago