Regular Expressions 101

Community Patterns

UK postcodes

0

Regular Expression
Python

r"
^((gir *0aa)|((((?![qvx])[a-z][a-hk-y]?[0-9][0-9]?)|(((?![qvx])[a-z][0-9][a-hjkstuw])|((?![qvx])[a-z][a-hk-y][0-9][abehmnprvwxy]))) *([0-9](?![cikmov])[a-z]{2}))|(((?![qvx])[a-z][a-hk-y]?[0-9][0-9]?)|((?![qvx])[a-z][0-9][a-hjkstuw])|((?![qvx])[a-z][a-hk-y][0-9][abehmnprvwxy])))$
"
igm

Description

Flexible regex to detect full or partial UK postcodes.

Submitted by Victor Munoz - 9 years ago