Friday, 1 February 2013

Somebody needs to improve their knowledge of regular expressions (case sensitivity)

UK post codes are quite hard to pin down. This is the official regex, from here:

(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})

There is no excuse for making them Upper Case only though (I know the regex above is case sensitive), just add (?i) to the start of the regex.


No comments:

Post a Comment