Regular Expressions 101

Community Patterns

City and POstcode

1

Regular Expression
PCRE (PHP <7.3)

/
[^a-z0-9]+\D\S\b (?>(?:[A-Za-z]\d ?\d[A-Za-z]{2})|(?:[A-Za-z][A-Za-z\d]\d ?\d[A-Za-z]{2})|(?:[A-Za-z]{2}\d{2} ?\d[A-Za-z]{2})|(?:[A-Za-z]\d[A-Za-z] ?\d[A-Za-z]{2})|(?:[A-Za-z]{2}\d[A-Za-z] ?\d[A-Za-z]{2}))
/
g

Description

Get city and postcode on the address string like input: 1 Amotherby Ln Amotherby Malton NORTH YORKSHIRE YO17 6TG UK output: NORTH YORKSHIRE YO17 6TG

Submitted by Michael Ramirez - 8 years ago