Regex Cheatsheet
Interactive regex cheatsheet where you can click patterns to test them live
regexcheatsheetreferencepatternguide
Live Regex Tester
//
3 matches
Hello 42 World 2024, regex is fun with 3 numbers!
Showing 56 of 56 entries
Character Classes
| Pattern | Description |
|---|---|
. | Any character except newline |
\w | Word character: [a-zA-Z0-9_] |
\W | Non-word character |
\d | Digit: [0-9] |
\D | Non-digit character |
\s | Whitespace: space, tab, newline |
\S | Non-whitespace character |
[abc] | Character in set a, b, or c |
[^abc] | Character not in set |
[a-z] | Character in range a through z |
[A-Z] | Character in range A through Z |
[0-9] | Digit character (same as \d) |
[a-zA-Z] | Any letter (upper or lower) |
Anchors
| Pattern | Description |
|---|---|
^ | Start of string (or line in multiline mode) |
$ | End of string (or line in multiline mode) |
\b | Word boundary |
\B | Non-word boundary |
\A | Absolute start of string (not affected by multiline) |
\Z | Absolute end of string |
Quantifiers
| Pattern | Description |
|---|---|
* | Zero or more of the preceding element |
+ | One or more of the preceding element |
? | Zero or one of the preceding element (optional) |
{n} | Exactly n repetitions |
{n,} | At least n repetitions |
{n,m} | Between n and m repetitions (inclusive) |
*? | Lazy: zero or more (as few as possible) |
+? | Lazy: one or more (as few as possible) |
?? | Lazy: zero or one (prefer zero) |
{n,m}? | Lazy version of bounded quantifier |
Groups & References
| Pattern | Description |
|---|---|
(abc) | Capturing group: captures the match |
(?:abc) | Non-capturing group: groups without capturing |
(?<name>abc) | Named capturing group |
\1, \2 | Backreference to captured group 1, 2, etc. |
\k<name> | Backreference to named group |
| | Alternation: matches either expression |
Lookahead & Lookbehind
| Pattern | Description |
|---|---|
(?=abc) | Positive lookahead: followed by abc |
(?!abc) | Negative lookahead: not followed by abc |
(?<=abc) | Positive lookbehind: preceded by abc |
(?<!abc) | Negative lookbehind: not preceded by abc |
Flags
| Pattern | Description |
|---|---|
g | Global: find all matches (not just first) |
i | Case-insensitive matching |
m | Multiline: ^ and $ match start/end of each line |
s | Dotall: . matches newline characters too |
u | Unicode: treat pattern as Unicode code points |
y | Sticky: match only from lastIndex position |
d | Indices: return start/end indices of matches |
Special Characters
| Pattern | Description |
|---|---|
\n | Newline character |
\t | Tab character |
\r | Carriage return |
\0 | Null character |
\uXXXX | Unicode character by hex code point |
\xHH | ASCII character by hex value |
\\ | Literal backslash |
\. | Literal dot (escaping special char) |
\( | Literal parenthesis |
\[ | Literal bracket |