Saturday 8 March 2008

Useful Regular Expressions for Recogonizers

Regular expressions can be a bit of a head scratcher if you haven't been exposed to them before, so if you are reading this and you want to have a play with the Recognizers in widgets here are some examples :-

UK Postal Codes:
^[A-Za-z]{1,2}[\d]{1,2}([A-Za-z])?\s?[\d][A-Za-z]{2}$

US Zip Codes (5 or 5-4)
^\d{5}$|^\d{5}-\d{4}$

IP Addresses :
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

ISBN Numbers :
^ISBN\s(?=[-0-9xX ]{13}$)(?:[0-9]+[- ]){3}[0-9]*[xX0-9]$

Date in the format 99/99/9999
^\d{1,2}\/\d{1,2}\/\d{4}$

USA Phone numbers in the format ANN-NNN-NNNN where A=2-9 and N=0-9
^[2-9]\d{2}-\d{3}-\d{4}$

I have opened up this page on the IBM LDD Wiki to be a resource for useful RegExps that might be worth sharing with the rest of the lotus world. So come on all you RegExp-ers and RegExp-ettes, please nip over to the page and add to the list. There is nothing like a good list of examples so that folk can get their heads around a new skill.

Steve

1 comment:

Anonymous said...

another really great site for regular expressions and help with regular expressions is www.regexlib.com

Disqus for Domi-No-Yes-Maybe