I'm after a regex that will validate a full complex UK postcode only within an input string. All of the uncommon postcode forms must be covered as well as the usual. For instance:
Matches
- CW3 9SS
- SE5 0EG
- SE50EG
- se5 0eg
- WC2H 7LT
No Match
- aWC2H 7LT
- WC2H 7LTa
- WC2H
Are there any official or even semi-official regexes in use for this kind of thing? Any other advice as to formatting and storing these in a database?