/\b((GIR0AA)|((([A-PR-UWYZ][0-9][0-9]?)|(([A-PR-UWYZ][A-HK-Y][0-9][0-9]?)|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY])))) ?[0-9][ABD-HJLNP-UW-Z]{2}))\b/ig
Matches UK postcodes (with or without spaces).
References: http://webarchive.nationalarchives.gov.uk/+/http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards/address/postcode.aspx
#+ Valid Postcodes
CW3 9SS
SE5 0EG
SE50EG
se5 0eg
WC2H 7LT
A post code in some text SE5 0EG is here
M1 1AA
B33 8TH
CR2 6XH
DN55 1PT
W1A 1HQ
EC1A 1BB
#- Invalid Post Codes
aWC2H 7LT
WC2H 7LTa
WC2H