Every time I try to do something with postcodes I find myself trying to remember the different potential formats and googling for effective regular expressions (the one I want is never in the first five I try).
I decided to record what I found to help out future me (and others). This post will:
- Point you to a much better article Programmer’s guide to UK postcodes
- Give a simple Python example for using regular expressions to extract parts of a UK postcode