I have a regular expression for checking whether a string is zip/postal code or not. But I would really like to also to be able to extract that from a full address (or, if possible, any string).
Here is my current regular expression:
/^((\d{5}-\d{4})|(\d{5})|([a-zA-Z]\d[a-zA-Z]\s\d[a-zA-Z]\d)|([a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d))$/
If necessary I'm willing to settle for a function (I'm checking with PHP) but I'd rather the regexp do the work if possible.