Regular Expression Quick Reference
Numbers
- ^-?\d+$
- A signed integer with no leading plus.
- ^\d{1,3}(,\d{3})*$
- Digits grouped in thousands with commas.
- ^0[xX][0-9a-fA-F]+$
- A hexadecimal literal.
Text
- ^\s+|\s+$
- Leading and trailing whitespace, for trimming.
- (\b\w+\b)\s+\1
- A word repeated twice in a row.
- ^[A-Z][a-z]+(?: [A-Z][a-z]+)*$
- Capitalised words separated by single spaces.
Structured values
- ^\d{4}-\d{2}-\d{2}$
- A calendar date in ISO 8601 form.
- ^([0-9]{1,3}\.){3}[0-9]{1,3}$
- Four dotted decimal octets, range not checked.
- ^#(?:[0-9a-f]{3}|[0-9a-f]{6})$
- A three or six digit colour literal.
Syntax notes follow the POSIX extended and PCRE conventions. Flavours differ in lookbehind and named group support.