A better postcode regexp

A couple of months ago I spent an evening making a Greasemonkey app that turns postcodes into links to maps. However, I’ve been told that it doesn’t capture every single postcode – it turns out the regular expression I used for postcodes isn’t quite right (it doesn’t catch, for example, W1U 2BF). Fortunately, I managed to find this standard specification, and so I’ve been able to fix it so that it does work. Hurrah! For anyone needing a regular expression for UK postcodes in any sort of application, the following actually works properly:

/\b[A-PR-UWYZ][A-HK-Y0-9][A-HJKSTUW0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}\b/g

(NB: This does not include the special case of the Gibraltar Girobank postcode, GIR 0AA)

The latest version is now 0.12 – those that already have the linkifier installed should reinstall it from here.