On Thu, Jan 02, 2003 at 03:29:43PM +0100, Abigail wrote:
> For the module Regexp::Common, I'm looking for the formats of
> zip (or postal) codes of various countries. Thanks to another
> mailing list, I've the formats for the Netherlands, Britain
> and Australia.
What do you have for Britain, and how precise/future-proof do you want
it to be?
When I was contructing a match for British postcodes, I based the
following pattern on the Govenment Datastandards Catalogue[*]
m/(^|\W)(([A-Za-z][0-9]|[A-Za-z][0-9]{2}|[A-Za-z][A-HJ-Ya-hj-y][0-9]|[A-Za-z][A-HJ-Ya-hj-y][0-9]{2}|[A-Za-z][0-9][A-Za-z]|[A-Za-z][A-HJ-Ya-hj-y][0-9][A-Za-z])\s+[0-9][ABD-HJLP-UW-Zabd-hjlp-uw-z]{2}|[Gg][iI][Rr]\W+0[aA]{2})(\W|$)/
Which will leave a postcode in $2. It can be made shorter/slower by
using /i and not repeating all of the letters in each case.
The only postcodes it does not cover is the Forces post codes, which are
of the format BFPO \d+
Sorry to not be helping you with a new country though.
David
[*] See page 12 of: http://xml.coverpages.org/govtalkCat2.pdf
--
Facts do not cease to exist because they are ignored.
-- Aldous Huxley