Community Patterns

Community Library Entry

0

Regular Expression
Created·2020-08-27 10:05
Flavor·PCRE (Legacy)

/
^([Gg][Ii][Rr] 0[Aa]{2})|((?:(?:[A-Za-z][0-9]{1,2})|(?:(?:[A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(?:(?:[A-Za-z][0-9][A-Za-z])|(?:[A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2})$
/
gm
Open regex in editor

Description

This is intended to be a relatively simple matching (anchored left and right) for a uk post code.

Please use the unit tests to run the examples. The examples are from wikipedia, but I shall try and keep it up to date.

Submitted by anonymous