Regex Cheatsheet
Searchable regex syntax reference with examples and copy buttons.
Basics
.Any character except newline
a.c matches abc
Character classes
\dAny digit (0-9)
\d+ matches 123
\DAny non-digit
\D+ matches abc
\wWord character (letter, digit, underscore)
\w+ matches hello_1
\WNon-word character
\W matches !
\sWhitespace character
a\sb matches 'a b'
\SNon-whitespace character
\S+ matches abc
[abc]Any of a, b, or c
[abc]+ matches cab
[^abc]Any character except a, b, c
[^abc] matches d
[a-z]Any lowercase letter
[a-z]+ matches hello
Anchors
^Start of string/line
^Hello matches 'Hello world'
$End of string/line
world$ matches 'Hello world'
\bWord boundary
\bcat\b matches 'a cat sat'
\BNon-word boundary
\Bcat matches 'concatenate'
Quantifiers
*0 or more of the previous token
ab*c matches ac, abc, abbc
+1 or more of the previous token
ab+c matches abc, abbc
?0 or 1 of the previous token (optional)
colou?r matches color, colour
{n}Exactly n repetitions
\d{3} matches 123
{n,}n or more repetitions
\d{2,} matches 12, 123
{n,m}Between n and m repetitions
\d{2,4} matches 12, 123, 1234
*?Lazy (non-greedy) 0 or more
<.*?> matches '<a>' first, not '<a><b>'
Groups
(abc)Capturing group
(ab)+ captures repeated 'ab'
(?:abc)Non-capturing group
(?:ab)+ groups without capturing
(?<name>abc)Named capturing group
(?<year>\d{4})
a|bAlternation — a or b
cat|dog matches cat or dog
Lookaround
(?=abc)Positive lookahead
\d(?=px) matches digit before 'px'
(?!abc)Negative lookahead
\d(?!px) matches digit not before 'px'
(?<=abc)Positive lookbehind
(?<=\$)\d+ matches digits after $
(?<!abc)Negative lookbehind
(?<!\$)\d+ matches digits not after $
Flags
gGlobal flag — find all matches
/a/g
iCase-insensitive flag
/abc/i matches ABC
mMultiline flag — ^ and $ match line boundaries
/^a/m
sDotall flag — . matches newlines too
/a.b/s
uUnicode flag
/\u{1F600}/u
About the Regex Cheatsheet
Browse a categorized, searchable reference of regular expression syntax — character classes, anchors, quantifiers, groups, lookaround, and flags — each with an example and a copy button.
Examples
Lookahead
lookaheadOutput
(?=abc) — positive lookaheadRelated tools
Regex Tester
Dev Utilities
Test regular expressions with live match highlighting.
Git Command Cheatsheet
Dev Utilities
Searchable reference of common git commands with copy buttons.
.htaccess Redirect Generator
Dev Utilities
Generate Apache .htaccess redirect and rewrite rules.
Chmod Calculator
Dev Utilities
Unix permission calculator: checkboxes, octal, and symbolic.
Code Comment Stripper
Dev Utilities
Remove comments from JS, HTML, Python, or SQL source.
Code Diff Merger
Dev Utilities
Side-by-side line diff of two code snippets with stats.
Frequently asked questions
Read more
- Writing safer regular expressions: avoiding catastrophic backtracking
ReDoS bugs come from a small number of recognizable patterns. Here's how to spot them and write regexes that stay fast on any input.
Version 1.0.0 · Updated 2026-08-06 · Runs entirely in your browser