Regular Expression Quick Reference
Shorthand
- \d
- Any decimal digit.
- \D
- Any character that is not a digit.
- \w
- Word character, letters digits and underscore.
- \W
- Any character that is not a word character.
- \s
- Whitespace including space tab and newline.
- \S
- Any character that is not whitespace.
- .
- Any character except newline unless the dotall flag is set.
Bracket expressions
- [abc]
- Any one of a, b or c.
- [^abc]
- Any character other than a, b or c.
- [a-z]
- Any character in the range a to z.
- [[:alpha:]]
- POSIX class for alphabetic characters.
- [[:xdigit:]]
- POSIX class for hexadecimal digits.
Flags
- i
- Case insensitive matching.
- m
- Multiline, anchors match at line breaks.
- s
- Dotall, the dot also matches newline.
- x
- Extended, ignore unescaped whitespace.
Syntax notes follow the POSIX extended and PCRE conventions. Flavours differ in lookbehind and named group support.