glunty

Regex Cheat Sheet

A searchable reference of regex syntax with tiny examples, grouped by category.

Regex tokens with their meaning and a short example
Token Meaning Example
\d Any digit from 0 to 9. \d+ matches 42
\D Any character that is not a digit. \D matches x in x9
\w A word character: letter, digit, or underscore. \w+ matches user_1
\W Any character that is not a word character. \W matches @ in a@b
\s Any whitespace: space, tab, newline, and similar. a\sb matches a b
\S Any character that is not whitespace. \S+ matches word
. Any single character except a line break. a.c matches abc
[abc] One character from the listed set. [abc] matches b
[^abc] One character that is not in the listed set. [^abc] matches d
[a-z] One character in the given range. [a-z] matches m
\t A tab character. \t matches a tab
\n A newline (line feed) character. \n matches a line break
^ Start of the string, or start of a line with the m flag. ^a matches a in abc
$ End of the string, or end of a line with the m flag. c$ matches c in abc
\b A word boundary between a word and a non-word character. \bcat\b matches cat
\B A position that is not a word boundary. \Bcat matches cat in scatter
\A Start of the string only (PCRE and Python, not JavaScript). \Afoo matches leading foo
\Z End of the string or just before a final newline (PCRE, Python). bar\Z matches trailing bar
\z The very end of the string with no exceptions (PCRE, Python). \z matches the very end
* Zero or more of the preceding token (greedy). a* matches aaa or empty
+ One or more of the preceding token (greedy). a+ matches aa
? Zero or one of the preceding token; makes it optional. ab?c matches ac
{n} Exactly n repetitions. a{3} matches aaa
{n,} At least n repetitions. a{2,} matches aaaa
{n,m} Between n and m repetitions. a{1,3} matches up to aaa
*? Lazy zero or more: matches as few as possible. a*? matches as few as it can
+? Lazy one or more: matches as few as possible. <.+?> stops at the first >
?? Lazy optional: prefers to match zero. a?? prefers zero a
{n,m}? Lazy bounded repetition: prefers the fewest. a{1,3}? prefers one a
(...) Capturing group; stores the matched text for reuse. (ab)+ captures ab
(?:...) Non-capturing group; groups without storing. (?:ab)+ groups without capture
(?<name>...) Named capturing group; capture under a name. (?<yr>\d{4}) captures 2026
\1 Backreference to the first captured group. (a)\1 matches aa
\2 Backreference to the second captured group. (a)(b)\2 matches abb
\k<name> Backreference to a named group. \k<yr> repeats a named group
| Alternation; matches the left or the right side. cat|dog matches dog
(?P<name>...) Python syntax for a named capturing group. Python: (?P<id>\d+)
(?=...) Positive lookahead; the following text must match. \d(?=px) matches 9 in 9px
(?!...) Negative lookahead; the following text must not match. q(?!u) skips q in qu
(?<=...) Positive lookbehind; the preceding text must match. (?<=@)\w+ matches the host
(?<!...) Negative lookbehind; the preceding text must not match. (?<!@)\w+ matches the user
g Global; find all matches instead of stopping at the first. /a/g finds every a
i Case-insensitive matching. /abc/i matches ABC
m Multiline; ^ and $ match at line breaks. /^a/m matches each line start
s Dotall; the dot also matches line breaks. /a.b/s lets dot span lines
u Unicode mode; enables code point and \p{...} handling. u enables \p{L} classes
y Sticky; match only at the current lastIndex. y matches at lastIndex only
x Extended; ignore whitespace and allow comments in the pattern. x ignores pattern whitespace
(?i) Inline flag; turn on case-insensitivity from this point. (?i)abc matches ABC
(?i:...) Scoped inline flag applied only to this group. (?i:abc) matches ABC inline
[\w.+-]+@[\w.-]+\.\w+ A simple email address pattern. matches name@site.com
https?://\S+ An http or https web address. matches https://a.io/x
(\d{1,3}\.){3}\d{1,3} Four dot-separated numbers (loose IPv4). matches 10.0.0.1
#[0-9a-fA-F]{3,6} A CSS hex color with 3 or 6 digits. matches #1a2b3c
\d{4}-\d{2}-\d{2} An ISO-style calendar date. matches 2026-07-04
\d{3}-\d{3}-\d{4} A US phone number with dashes. matches 555-123-4567
^\s+|\s+$ Leading or trailing whitespace to strip. trims both ends of a line
^\d+$ A string that is only digits. matches 42, rejects 4a
([01]\d|2[0-3]):[0-5]\d A 24-hour clock time. matches 23:59
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} A version 4 style UUID. matches a UUID string

Runs entirely in your browser. Nothing you type is sent anywhere; open DevTools and watch the Network tab to verify zero requests.

What this tool does

This is a searchable cheat sheet for regular expressions. Each row lists a token or a ready-made pattern, a plain-English meaning, and a tiny example so you can see it in action. Use the category buttons to move between character classes, anchors, quantifiers, groups, lookaround, flags, and common patterns. Everything is baked into the page, so it works offline and sends nothing anywhere.

How to use it

Start typing in the Filter box to narrow the table by token, meaning, or example text; entering lazy surfaces the lazy quantifiers, and entering email jumps to the email pattern. The category buttons (All, Classes, Anchors, Quantifiers, Groups, Lookaround, Flags, Common) combine with the text filter, so you can pick Quantifiers and type lazy at the same time. The live count shows how many tokens match, and clearing the box brings the full list back. Copy any token straight into your editor or the linked regex tester.

Common use cases

  • Remembering the exact syntax for a named group or a lazy quantifier.
  • Grabbing a ready-made pattern for an email, URL, date, or IPv4 address.
  • Checking whether a token like \A or a possessive quantifier exists in your regex flavor.
  • Teaching or reviewing regex with short, concrete examples.
  • Building a pattern piece by piece before testing it live.

Common pitfalls

  • Greedy by default. The quantifiers * and + grab as much text as they can. Add a ? (for example .+?) when you want the shortest match, or you may swallow far more than you intended.
  • Forgetting to escape. Characters such as . ( ) [ ] + * ? ^ $ | and the backslash are special. To match one literally, put a backslash in front, so \. matches a real dot and \( matches a real parenthesis.
  • Flavor differences. Named groups, \A and \Z, lookbehind, and possessive quantifiers are not supported everywhere. Confirm your engine (JavaScript, Python, PCRE) before you ship a pattern.
  • Catastrophic backtracking. Nested quantifiers over overlapping text, such as (a+)+ against a long non-matching string, can make matching blow up exponentially. Prefer specific character classes, atomic groups, or possessive quantifiers where your engine supports them.

Frequently asked questions

What is a regex character class?
A character class matches a single character from a set. Square brackets list the options, so [aeiou] matches any one vowel and [0-9] matches any one digit. Shorthand classes cover common sets: \d is a digit, \w is a word character, and \s is whitespace. A caret just inside the brackets negates the set, so [^0-9] matches any non-digit.
What is the difference between greedy and lazy quantifiers?
By default quantifiers like * and + are greedy: they match as much text as possible, then backtrack if the rest of the pattern needs it. Adding a ? makes them lazy, so they match as little as possible and expand only when forced. Against the input <a><b>, the pattern <.+> greedily grabs the whole string, while <.+?> stops at the first closing bracket.
What does \b mean in regex?
\b matches a word boundary, the zero-width position between a word character (\w) and a non-word character or the edge of the string. It matches no characters itself; it only asserts a position. So \bcat\b matches cat as a whole word but not the cat inside scatter. Its opposite, \B, matches anywhere that is not a word boundary.
What is the difference between (?:...) and (...)?
Both group part of a pattern so a quantifier or alternation applies to the whole group. Plain parentheses (...) also capture the matched text into a numbered group you can reference later with \1 or read from the result. The non-capturing form (?:...) groups without capturing, which keeps your group numbers tidy and can be a little faster. Use capturing when you need the value, and non-capturing when you only need grouping.
What are lookaheads and lookbehinds for?
Lookarounds assert that text does or does not appear near the current position without consuming it. A positive lookahead (?=...) requires what follows to match, while a negative lookahead (?!...) requires it not to. Lookbehind, written (?<=...) and (?<!...), does the same for text just before the position. They are handy for rules like match a number only when it is followed by px, without including px in the match.
Are these patterns the same in JavaScript, Python, and PCRE?
The core syntax on this page is shared across most flavors, but details differ. Named groups are (?<name>...) in JavaScript and PCRE but (?P<name>...) in Python, and \A, \Z, and possessive quantifiers exist in PCRE and Python yet not in JavaScript. Flags and inline modifiers also vary between engines. Always test against your specific engine before relying on an edge case.
Does this tool send what I type anywhere?
No. The entire cheat sheet is baked into the page, and the search box filters rows locally with JavaScript. Nothing you type leaves your device. You can confirm it by opening DevTools and watching the Network tab: filtering makes zero requests.

Embed this tool

Free for any use; attribution appreciated. Paste this on your site:

The embed runs the same tool that lives at this URL. No tracking; no ads inside the embed. Resize height as needed for your layout.

Cite this tool

For academic, journalistic, or technical references. Pick a format:

Citations use 2026 as the publication year. Access date is left as a fillable placeholder where the citation style expects one.

Embedded tool from glunty.com