fanf: (Default)
[personal profile] fanf

A little contribution for anyone else who searches the web for this in the future.

The UK postcode consists of two parts. The first part is the Outward Postcode, or Outcode. This is separated by a single space from the second part which is the Inward Postcode, or Incode. The Outcode directs mail to the correct local area for delivery. The Incode is used to sort the mail at the local area delivery office.

The Outcode has 6 possible formats (as follows) and the Incode is consistently numeric, alpha, alpha format.

  • AN NAA
  • ANN NAA
  • ANA NAA
  • AAN NAA
  • AANN NAA
  • AANA NAA

There are some restrictions on the letters:

  1. The letters [QVX] are not used in the first position.
  2. The letters [IJZ] are not used in the second position.
  3. The only letters to appear in the third position are [ABCDEFGHJKSTUW].
  4. The only letters to appear in the fourth position are [ABEHMNPRVWXY].
  5. The letters [CIKMOV] are not used in the second part.

This translates into a perl extended regex as follows (with slightly relaxed whitespace):

qr{\b
    ([A-PR-UWYZ]\d[\dA-HJKSTUW]? # rules 1,3
    |[A-PR-UWYZ][A-HK-Y]\d[\dABEHMNPRVWXY]? # rules 1,2,4
    )[\t ]{1,2}
    (\d[ABD-HJLNP-UW-Z]{2}) # rule 5
\b}x

Update: more here.

Date: 2008-08-28 19:47 (UTC)
bens_dad: (Default)
From: [personal profile] bens_dad
They certainly do letter recognition by computer.
I remember being impressed, a decade ago, to hear that they
computer sort letters by post code whilst the letters are moving at 40mph !

June 2025

S M T W T F S
1234567
8 91011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated 2025-06-13 11:55
Powered by Dreamwidth Studios