http://www.perlmonks.org?node_id=449971

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

A quickie regarding UK postcode (zip) validation... Is it possible to do the following 3 transformations in one regex or am I asking too much !
Typical UK postcode : LE12 3GX

1.Insert a space before the last 3 characters if there isn't one there already.

2.If the first character of the second part (3 characters as above) is a letter O, swap this to a zero.(this is a very common error)

3. uc() the whole thing.

The final result would pass the validation: /^[A-Z]{1,2}\d{1,2}([A-Z])?\s\d[A-Z]{2}$/

TIA