Quick reference
Character classes
| [abc] | A single character of: a, b or c | cat, bat |
| [^abc] | A character except: a, b or c | dog, fog |
| [a-z] | A character in the range: a-z | lowercase word |
| \d | Any digit (0-9) | 42 |
| \w | Any word character (a-z, A-Z, 0-9, _) | hello_42 |
| \s | Any whitespace character | a b\tc |
Quantifiers
| a* | Zero or more of a | aaab |
| a+ | One or more of a | aaab |
| a? | Zero or one of a (optional) | color / colour |
| a{3} | Exactly 3 of a | aaa |
| a{2,} | 2 or more of a | aaaa |
| a{2,4} | Between 2 and 4 of a | aa, aaa, aaaa |
Anchors
| ^ | Start of string | ^abc |
| $ | End of string | abc$ |
| \b | Word boundary | \bcat\b |
| \B | Not a word boundary | \Bcat |
Groups and references
| (abc) | Capturing group | (\d{4})-(\d{2}) |
| (?:abc) | Non-capturing group | (?:foo|bar) |
| (?<name>abc) | Named capturing group | (?<year>\d{4}) |
| \1 | Backreference to group 1 | (a|b)\1 |