Commonly used regular expressions - Cheatsheet

Updated . Posted . Visible to the public.

For Email-Patterns see most recent E-Mail-Pattern.

HOST = /\A[a-z0-9]+[a-z0-9\-\.]*[a-z0-9]+\z/i
BANK_CODE = /\A\d{8}\z/                                          # Germany
BANK_ACCOUNT_NUMBER = /\A\d{1,10}\z/                             # Germany
ZIP_CODE = /\A\d{5}\z/                                           # Germany
HEX_COLOR = /\A([a-fA-F0-9]{3}){1,2}\z/
IP_ADDRESS = /\A(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)(?:\.(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)){3}\z/

We usually put these constants in a Pattern class, so we can call them like Pattern::EMAIL.

Martin Straub
Last edit
Judith Roth
Keywords
regex
License
Source code in this card is licensed under the MIT License.
Posted by Martin Straub to makandra dev (2011-06-09 07:56)