Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
\d+(?:(?:\s?[a-zA-Z]+)+(?:,|\s)+)+(?:[A-Za-z][A-Ha-hK-Yk-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})
/
gms

Description

Matches single line and mutliline UK postal address as long as they start with a number. For example:

1 Test Street Test Town AA1 1AA

32 Island Road, Placington, AA2 2AA

Submitted by anonymous - 6 years ago