Skip to content
Free Tool Arena

Glossary · Definition

Regex cheat sheet

Quick regex reference. Character classes: <code>\d</code> digit, <code>\w</code> word, <code>\s</code> whitespace. Quantifiers: <code>*</code> 0+, <code>+</code> 1+, <code>?</code> 0-1, <code>&#123;n,m&#125;</code> range. Anchors: <code>^</code> start, <code>$</code> end, <code>\b</code> word-boundary. Groups: <code>(...)</code> capture, <code>(?:...)</code> non-capture, <code>(?&lt;name&gt;...)</code> named.

Updated May 2026 · 4 min read
100% in-browserNo downloadsNo sign-upMalware-freeHow we keep this safe →

Definition

Quick regex reference. Character classes: <code>\d</code> digit, <code>\w</code> word, <code>\s</code> whitespace. Quantifiers: <code>*</code> 0+, <code>+</code> 1+, <code>?</code> 0-1, <code>&#123;n,m&#125;</code> range. Anchors: <code>^</code> start, <code>$</code> end, <code>\b</code> word-boundary. Groups: <code>(...)</code> capture, <code>(?:...)</code> non-capture, <code>(?&lt;name&gt;...)</code> named.

What it means

<strong>Character classes</strong>: <code>\d</code> = [0-9], <code>\D</code> = non-digit, <code>\w</code> = [A-Za-z0-9_], <code>\W</code> = non-word, <code>\s</code> = whitespace, <code>\S</code> = non-whitespace, <code>.</code> = any char (except newline by default). <strong>Custom classes</strong>: <code>[abc]</code> any of, <code>[a-z]</code> range, <code>[^abc]</code> negation. <strong>Quantifiers</strong>: <code>*</code> 0+, <code>+</code> 1+, <code>?</code> 0-1, <code>&#123;n&#125;</code> exactly n, <code>&#123;n,m&#125;</code> n to m. Lazy variants: <code>*?</code>, <code>+?</code>. <strong>Anchors</strong>: <code>^</code> string/line start, <code>$</code> string/line end, <code>\b</code> word boundary. <strong>Groups</strong>: <code>(...)</code> capture, <code>(?:...)</code> non-capture, <code>(?&lt;name&gt;...)</code> named, <code>(?=...)</code> lookahead, <code>(?!...)</code> negative lookahead, <code>(?&lt;=...)</code> lookbehind. <strong>Flags</strong>: <code>i</code> case-insensitive, <code>g</code> global, <code>m</code> multiline (^/$ match line bounds), <code>s</code> dotall (. matches newlines), <code>u</code> unicode.

Advertisement

Why it matters

Regex is universally useful but easy to write wrong. Common patterns memorized save time. Always test patterns interactively before deploying. The cheat sheet covers ECMAScript / JavaScript regex; PCRE (PHP, Java, .NET) and Python re have slightly different feature sets — PCRE adds recursive patterns and possessive quantifiers; Python re adds named-group access via dict.

Example

Email (rough): <code>\b[\w.+-]+@[\w-]+\.[\w.-]+\b</code>. URL: <code>https?:\/\/[\w.-]+(?:\/[^\s]*)?</code>. US phone: <code>\(?\d&#123;3&#125;\)?[\s.-]?\d&#123;3&#125;[\s.-]?\d&#123;4&#125;</code>. IPv4: <code>(?:25[0-5]|2[0-4]\d|[01]?\d\d?)(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?))&#123;3&#125;</code>.

Related free tools

Frequently asked questions

Greedy vs lazy quantifiers?

Greedy (default): match as much as possible, then back off. Lazy: match as little as possible. <code>.*</code> on <code>&lt;a&gt;&lt;b&gt;</code> matches everything; <code>.*?</code> matches just <code>&lt;a&gt;</code>.

When to use lookahead vs capture group?

Lookahead (<code>(?=...)</code>): zero-width assertion, doesn&rsquo;t consume characters. Capture group: extracts matched text. Use lookahead for &lsquo;match X but only if followed by Y&rsquo; without consuming Y.

Why does my regex behave differently in JavaScript vs Python?

Different dialects. Lookbehind syntax differs slightly; Unicode handling differs (especially with <code>\d</code>, which is ASCII-only in default JS but Unicode-aware in Python). Always test in your target language.

Related terms