Any character
Matches any single character except a line break.
./c.t/ matches "cat", "cot" and "c9t"
With the s flag, . also matches line breaks.
Regular expression syntax with tested examples: classes, quantifiers, anchors, groups, lookarounds, flags and common patterns.
Regex Cheatsheet · Helper-Kit
Examples use JavaScript syntax. Most of it works the same in Python, Java, C#, PHP and Go; lookbehind and named groups vary slightly.
45 entries
Matches any single character except a line break.
./c.t/ matches "cat", "cot" and "c9t"
With the s flag, . also matches line breaks.
Matches a single character from the set.
[abc]/gr[ae]y/ matches "gray" and "grey"
Matches a single character that is not in the set.
[^abc]/[^0-9]/ matches the first non-digit
Matches a character in the range. Ranges can be combined.
[a-z] [A-Z] [0-9] [a-zA-Z0-9]/[A-F0-9]/ matches one hex digit (uppercase)
\d is the same as [0-9].
\d \D/\d+/ matches "2026" in "Year 2026"
\w is the same as [A-Za-z0-9_]. It does not include accented letters.
\w \W/\w+/ matches "user_1" in "user_1@site"
Space, tab, line break and other spacing characters.
\s \S/\s+/ matches the gap in "a b"
Tab, new line (Unix), carriage return + new line (Windows).
\t \n \r\nAny letter in any language. Needs the u flag.
\p{L}/\p{L}+/u matches "café" and "Ålesund"
The previous item, any number of times (including none).
*/ab*c/ matches "ac", "abc", "abbbc"
The previous item at least once.
+/ab+c/ matches "abc", "abbc" but not "ac"
The previous item zero or one time.
?/colou?r/ matches "color" and "colour"
Exactly n, at least n, or between n and m times.
{n} {n,} {n,m}/\d{3}-\d{4}/ matches "555-1234"
Add ? after a quantifier to stop at the first possible match.
*? +? ?? {n,m}?/<.+?>/ matches "<b>" in "<b>bold</b>", not the whole string
Start and end of the text. With the m flag: start and end of each line.
^ $/^\d+$/ matches only if the whole text is digits
The edge between a word character and a non-word character.
\b \B/\bcat\b/ matches "cat" in "a cat sat" but not in "concat"
Matches the left side or the right side.
a|b/cat|dog/ matches "cat" or "dog"
Groups part of the pattern and saves what it matched.
(abc)/(\d{4})-(\d{2})/ on "2026-10" captures "2026" and "10"
Groups for quantifiers or | without saving the match.
(?:abc)/(?:ha)+/ matches "hahaha"
A capture group you can refer to by name.
(?<name>abc)/(?<year>\d{4})/ → match.groups.year
Matches the same text a group matched earlier.
\1 \k<name>/(\w)\1/ matches "ll" in "hello"
Insert captured groups into the replacement text.
$1 $<name> $&"2026-10-13".replace(/(\d+)-(\d+)-(\d+)/, "$3/$2/$1") → "13/10/2026"
Matches only if followed by the pattern, without including it.
x(?=y)/\d+(?=px)/ matches "16" in "16px"
Matches only if not followed by the pattern.
x(?!y)/\d+(?!px|\d)/ matches "2" in "2em", not "16" in "16px"
Matches only if preceded by the pattern.
(?<=y)x/(?<=\$)\d+/ matches "25" in "$25"
Matches only if not preceded by the pattern.
(?<!y)x/(?<!\$)\b\d+/ matches "3" in "$25 for 3"
Find every match, not only the first.
/pattern/gUppercase and lowercase match each other.
/pattern/i^ and $ match at the start and end of every line.
/pattern/mLets . match \n too.
/pattern/sCorrect handling of emoji and other characters, and enables \p{…}.
/pattern/uPut a backslash before these to match them literally.
\. \* \+ \? \^ \$ \( \) \[ \] \{ \} \| \\ \//example\.com/ matches "example.com" but not "exampleXcom"
In /…/ literals, escape the slash. In new RegExp("…") strings, double the backslashes instead.
/https?:\/\//
new RegExp("\\d+")Something@something.something. Good for catching typos, not for full validation.
^[^\s@]+@[^\s@]+\.[^\s@]+$The only real test of an email address is sending a message to it.
http or https links.
https?:\/\/[\w.-]+(?:\.[a-z]{2,})(?:[\/?#][^\s]*)?matches "https://example.com/page?x=1"
Checks the shape and month/day ranges, not real dates like 31 February.
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$00:00 to 23:59.
^([01]\d|2[0-3]):[0-5]\d$#fff or #ffffff.
^#(?:[0-9a-fA-F]{3}){1,2}$Four numbers from 0 to 255.
^((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$At least 8 characters with a lowercase letter, an uppercase letter and a digit.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$Two or more spaces in a row, or spaces at the start or end of a line.
{2,}
^\s+|\s+$Returns true or false.
/^\d+$/.test("123") // trueThe first match with groups, or every match with the g flag.
"a1b22".match(/\d+/) // ["1", …]
"a1b22".match(/\d+/g) // ["1", "22"]
[..."a1b22".matchAll(/\d+/g)]Replace the first match, or all of them with g.
"a-b-c".replace(/-/g, "_") // "a_b_c"Split text on a pattern.
"a, b;c".split(/[,;]\s*/) // ["a", "b", "c"]💡 Search matches titles, descriptions and the commands themselves. Copy puts the exact text on your clipboard; Print gives a clean sheet without menus or buttons. Searching happens in your browser; nothing is sent anywhere.
Regular expressions (regex) describe text patterns, so you can find, check or replace text: every email address in a file, dates in a certain format, or extra spaces. This cheatsheet covers characters and classes, quantifiers, anchors, groups and back-references, lookarounds, flags, escaping, ready-made patterns and how to use regex in JavaScript. Every example shows a pattern and what it matches, and every example on this page has been tested. The syntax is JavaScript's, which is shared by most languages; lookbehind and named groups vary slightly between them. To try a pattern on your own text, open it in the Regex Tester.
* matches the previous item zero or more times, so it can match nothing. + needs at least one.
Quantifiers are greedy and take as much as they can. Add ? to make them lazy: <.+?> stops at the first >.
Add the i flag: /hello/i matches "Hello" and "HELLO". In new RegExp() pass "i" as the second argument.
Brackets ( ) group part of a pattern and save what it matched, so you can read it later or use it in a replacement as $1, $2 and so on.