Zero Signup ToolsFree browser tools

Developer Tools

Regex Cheat Sheet

Browseable regex cheat sheet for JavaScript with anchors, character classes, quantifiers, groups, lookaround, flags, and copy-ready common patterns.

Section

Showing 57 of 57 entries. Every entry is live: edit the test input and the highlights update.

Quick playground

Live in your browser

Try any pattern from the cheat sheet here without leaving the page. Paste your own input, edit the pattern, and see every match highlighted as you type. For a fuller workflow with capture groups and a replace preview, open the regex tester.

Highlighted result

Contact alice@example.com and bob@example.org for details, or write to the team.

2 matches found.

Anchors

4 entries

Match a position in the input rather than a character. Useful for pinning a pattern to the start or end of a line, a string, or a word boundary.

  • ^

    Start of string (or line with m flag)

    Matches the position at the start of the input. With the m flag, matches the start of every line.

    Pattern

    /^Hello/g

    Highlighted result

    Hello world
    Hello again

    1 match found.

  • $

    End of string (or line with m flag)

    Matches the position at the end of the input. With the m flag, matches the end of every line.

    Pattern

    /world$/g

    Highlighted result

    the world

    1 match found.

  • \b

    Word boundary

    Matches the position between a word character (alphanumeric or underscore) and a non-word character. Use it to match whole words.

    Pattern

    /\bcat\b/g

    Highlighted result

    a cat in a category

    1 match found.

  • \B

    Non-word boundary

    The inverse of \b. Matches a position that is not a word boundary, useful for substring matches inside words.

    Pattern

    /\Bcat/g

    Highlighted result

    category locate

    1 match found.

Character classes

5 entries

Match one character from a set. Use square brackets to define your own set, or combine ranges and negation for precise matches.

  • [abc]

    Any one listed character

    Matches a single character that is a, b, or c. Order does not matter.

    Pattern

    /[abc]/g

    Highlighted result

    aabcXYZcab

    7 matches found.

  • [^abc]

    Any character not in the set

    The caret at the start of a class negates it. Matches one character that is not a, b, or c.

    Pattern

    /[^abc]/g

    Highlighted result

    abcXYZcab

    3 matches found.

  • [a-z]

    Character range

    Matches one character in the inclusive range a through z. Combine ranges like [A-Za-z0-9_].

    Pattern

    /[a-z]+/g

    Highlighted result

    Hello 42 World

    2 matches found.

  • [A-F0-9]

    Multiple ranges

    Combine ranges in one class. This one matches one uppercase hex digit.

    Pattern

    /[A-F0-9]+/g

    Highlighted result

    ID 7F3C and GHI

    2 matches found.

  • .

    Any character except newline

    Matches any single character except line terminators. Use the s flag to also match newlines.

    Pattern

    /h.t/g

    Highlighted result

    hot hat hit h
    t

    3 matches found.

Shorthand character classes

6 entries

Predefined classes that cover the most common character buckets. Lowercase forms match the class; uppercase forms match the inverse.

  • \d

    Digit

    Matches any digit. Equivalent to [0-9] in ASCII. With the u flag, also matches digits from other scripts.

    Pattern

    /\d+/g

    Highlighted result

    Room 101 floor 2

    2 matches found.

  • \D

    Non-digit

    Matches any character that is not a digit. Equivalent to [^0-9].

    Pattern

    /\D+/g

    Highlighted result

    abc123def

    2 matches found.

  • \w

    Word character

    Matches any letter, digit, or underscore. Equivalent to [A-Za-z0-9_] in ASCII.

    Pattern

    /\w+/g

    Highlighted result

    hello_world! 123 .foo

    3 matches found.

  • \W

    Non-word character

    Matches anything that is not a letter, digit, or underscore.

    Pattern

    /\W/g

    Highlighted result

    a-b_c d.e

    3 matches found.

  • \s

    Whitespace

    Matches any whitespace character: space, tab, newline, carriage return, form feed.

    Pattern

    /\s+/g

    Highlighted result

    one  two	three
    four

    3 matches found.

  • \S

    Non-whitespace

    Matches any character that is not whitespace.

    Pattern

    /\S+/g

    Highlighted result

    one  two	three

    3 matches found.

Quantifiers

8 entries

Repeat the previous element. Add a question mark to a quantifier to make it lazy (smallest match) instead of greedy (largest match).

  • ?

    Zero or one

    Matches the previous element zero or one times. Makes that element optional.

    Pattern

    /colou?r/g

    Highlighted result

    color and colour

    2 matches found.

  • *

    Zero or more

    Matches the previous element zero or more times. Greedy by default.

    Pattern

    /ab*/g

    Highlighted result

    a ab abb abbb

    4 matches found.

  • +

    One or more

    Matches the previous element one or more times. Greedy by default.

    Pattern

    /ab+/g

    Highlighted result

    a ab abb abbb

    3 matches found.

  • {n}

    Exactly n times

    Matches the previous element exactly n times.

    Pattern

    /a{3}/g

    Highlighted result

    a aa aaa aaaa

    2 matches found.

  • {n,}

    n or more times

    Matches the previous element at least n times.

    Pattern

    /a{2,}/g

    Highlighted result

    a aa aaa aaaa

    3 matches found.

  • {n,m}

    Between n and m times

    Matches the previous element between n and m times (inclusive).

    Pattern

    /a{2,3}/g

    Highlighted result

    a aa aaa aaaa

    3 matches found.

  • *?

    Lazy zero or more

    The lazy form of *. Matches as few characters as possible while still allowing the overall pattern to succeed.

    Pattern

    /<.*?>/g

    Highlighted result

    <b>bold</b><i>i</i>

    4 matches found.

  • +?

    Lazy one or more

    The lazy form of +. Matches as little as possible.

    Pattern

    /a.+?b/g

    Highlighted result

    axxxbyyyb

    1 match found.

Groups and references

5 entries

Group parts of a pattern to apply quantifiers to them, capture their match for reuse, or organize alternation.

  • (abc)

    Capturing group

    Groups elements together and captures the matched text into a numbered group, available via match[1], match[2], etc.

    Numbered groups are assigned in left-to-right order based on their opening parenthesis.

    Pattern

    /(\w+)@(\w+)/g

    Highlighted result

    user@example

    1 match found.

  • (?:abc)

    Non-capturing group

    Groups elements without capturing them. Useful when you need grouping for quantifiers or alternation but do not need the captured text.

    Pattern

    /(?:ha){2,}/g

    Highlighted result

    haha hahaha h

    2 matches found.

  • (?<name>abc)

    Named capturing group

    Captures the match into a group accessible by name through match.groups.name. Available in modern JavaScript.

    Pattern

    /(?<year>\d{4})-(?<month>\d{2})/g

    Highlighted result

    2026-06 release

    1 match found.

  • \1

    Backreference

    References a previously captured group by its number. The pattern matches only if the same text appears again.

    Pattern

    /(\w)\1/g

    Highlighted result

    letter book mood

    3 matches found.

  • \k<name>

    Named backreference

    References a named group by its name.

    Pattern

    /(?<dup>\w)\k<dup>/g

    Highlighted result

    feet door room

    3 matches found.

Alternation

2 entries

Match one option from a list. The vertical bar acts like a logical OR. Combine with groups to limit its scope.

  • a|b

    Alternation

    Matches a or b. With no surrounding group, alternation has the lowest precedence and applies across the whole pattern.

    Pattern

    /cat|dog/g

    Highlighted result

    cat dog fish dog

    3 matches found.

  • (cat|dog)s

    Grouped alternation

    Without the group, the s would only attach to dog. The group binds the alternation tightly, so both branches share the trailing s.

    Pattern

    /(cat|dog)s/g

    Highlighted result

    cats dogs catdog

    2 matches found.

Lookahead and lookbehind

4 entries

Zero-width assertions that match a position based on what follows or precedes it. The asserted text is not consumed by the match.

  • (?=...)

    Positive lookahead

    Matches the current position if the inner pattern matches what comes next, but does not consume it.

    Pattern

    /\d+(?=px)/g

    Highlighted result

    12px 34em 56px

    2 matches found.

  • (?!...)

    Negative lookahead

    Matches the current position only if the inner pattern does not match what comes next.

    Pattern

    /\d+(?!px)/g

    Highlighted result

    12px 34em 56px

    3 matches found.

  • (?<=...)

    Positive lookbehind

    Matches the current position only if the inner pattern matches what comes before. Supported in modern JavaScript engines.

    Pattern

    /(?<=\$)\d+/g

    Highlighted result

    items: $42, $7

    2 matches found.

  • (?<!...)

    Negative lookbehind

    Matches only if the inner pattern does not appear immediately before.

    Pattern

    /(?<!\$)\d+/g

    Highlighted result

    year 2026 cost $42

    2 matches found.

Escapes and special characters

5 entries

Use a backslash to escape characters that have a special regex meaning, or to insert special characters by their code.

  • \.

    Literal dot

    Escape any metacharacter to match it literally. Same idea for \+, \*, \?, \(, \), \[, \], \{, \}, \|, \^, \$, \\.

    Pattern

    /\d+\.\d+/g

    Highlighted result

    v1.2 and 3 dot 4

    1 match found.

  • \n

    Newline

    Matches a newline character (LF, U+000A). \r matches carriage return, \t a tab, \f a form feed.

    Pattern

    /line\n/g

    Highlighted result

    line
    break

    1 match found.

  • \t

    Tab

    Matches a tab character (U+0009).

    Pattern

    /\w+\t\w+/g

    Highlighted result

    name	value

    1 match found.

  • \xNN

    Hex character escape

    Matches the character with the given two-digit hex code. \x41 matches A.

    Pattern

    /\x41+/g

    Highlighted result

    AAAB CC

    1 match found.

  • \uNNNN

    Unicode hex escape

    Matches the character with the given four-digit hex code. \u00e9 matches the letter e with acute accent.

    Pattern

    /\u00e9/g

    Highlighted result

    café résumé

    3 matches found.

Flags

6 entries

Modifiers that change how the entire pattern is interpreted. In a JavaScript regex literal they appear after the closing slash, like /pattern/gi.

  • g

    Global

    Find all matches rather than stopping at the first. Required for matchAll and for replace with multiple replacements.

    Pattern

    /ab/g

    Highlighted result

    ab ab ab

    3 matches found.

  • i

    Case insensitive

    ASCII case-insensitive matching. With the u flag, case-folding is Unicode-aware.

    Pattern

    /hello/gi

    Highlighted result

    Hello HELLO heLLo

    3 matches found.

  • m

    Multiline

    Makes ^ and $ match the start and end of every line, not just the whole string.

    Pattern

    /^line/gm

    Highlighted result

    line one
    line two

    2 matches found.

  • s

    Dotall

    Makes . match newline characters as well as everything else.

    Pattern

    /a.b/s

    Highlighted result

    a
    b

    1 match found.

  • u

    Unicode

    Treats the pattern as a sequence of Unicode code points, enables \p{...} property escapes, and tightens escape validation.

    Pattern

    /\u{1F600}/u

    Highlighted result

    smile 😀!

    1 match found.

  • y

    Sticky

    Matches only at lastIndex. Useful for token-by-token parsers where each match must continue from the previous one.

    Pattern

    /\w+/y

    Highlighted result

    abc def

    1 match found.

Unicode property escapes

4 entries

With the u flag, you can match characters by their Unicode property: script, general category, etc. Modern JavaScript engines support these.

  • \p{L}

    Any letter

    Matches any character classified as a letter in Unicode, including non-Latin scripts.

    Pattern

    /\p{L}+/gu

    Highlighted result

    Hello 世界 été

    3 matches found.

  • \p{N}

    Any number

    Matches any character with the Unicode Number general category, including digits from many scripts.

    Pattern

    /\p{N}+/gu

    Highlighted result

    abc 12 १२३

    2 matches found.

  • \p{Script=Greek}

    Script property

    Matches characters from a specific Unicode script. Replace Greek with Latin, Cyrillic, Arabic, Han, and so on.

    Pattern

    /\p{Script=Greek}+/gu

    Highlighted result

    math πr² and area

    1 match found.

  • \P{L}

    Negated property

    Capital P negates the property class. \P{L} matches anything that is not a letter.

    Pattern

    /\P{L}+/gu

    Highlighted result

    Hello, World!

    2 matches found.

Common patterns

8 entries

Battle-tested regexes for everyday parsing and validation tasks. Copy the pattern, drop it into your code, and adjust if your input is unusual.

  • ^\S+@\S+\.\S+$

    Simple email

    Pragmatic email match: one or more non-whitespace chars, an @, one or more non-whitespace chars, a dot, then more. Good for form validation. For strict RFC compliance, send a verification email instead.

    Pattern

    /^\S+@\S+\.\S+$/g

    Highlighted result

    user@example.com

    1 match found.

  • https?://[^\s]+

    URL

    Matches an http or https URL up to the next whitespace character.

    Pattern

    /https?://[^\s]+/g

    Highlighted result

    Visit https://example.com or http://a.b/x

    2 matches found.

  • ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

    Hex color

    Matches a 3 or 6 character hex color, optionally prefixed with a hash.

    Pattern

    /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/g

    Highlighted result

    #1A2B3C

    1 match found.

  • ^\d{4}-\d{2}-\d{2}$

    ISO 8601 date

    Matches a YYYY-MM-DD date. Does not validate that the day exists in that month.

    Pattern

    /^\d{4}-\d{2}-\d{2}$/g

    Highlighted result

    2026-06-04

    1 match found.

  • ^(\d{1,3}\.){3}\d{1,3}$

    IPv4 address (loose)

    Matches the shape of an IPv4 address. Each octet may be 1 to 3 digits; this does not check that each octet is 0 to 255.

    Pattern

    /^(\d{1,3}\.){3}\d{1,3}$/g

    Highlighted result

    192.168.1.1

    1 match found.

  • ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$

    UUID

    Matches a canonical UUID with hyphens. Does not enforce the version nibble.

    Pattern

    /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/g

    Highlighted result

    550e8400-e29b-41d4-a716-446655440000

    1 match found.

  • ^[\w.-]+$

    Slug-safe identifier

    Letters, digits, underscore, dot, and hyphen only. Useful for filenames and URL slugs.

    Pattern

    /^[\w.-]+$/g

    Highlighted result

    post-2026_06.md

    1 match found.

  • ^\+?[1-9]\d{6,14}$

    Phone number (E.164)

    Matches an E.164 international phone number: optional plus sign, 7 to 15 digits, no leading zero.

    Pattern

    /^\+?[1-9]\d{6,14}$/g

    Highlighted result

    +14155552671

    1 match found.

Regex syntax notes

  • JavaScript regex literals look like /pattern/flags. The constructor form new RegExp("pattern", "flags") needs every backslash doubled inside the string: /\d+/ becomes new RegExp("\\\\d+").
  • Greedy quantifiers (*, +, {n,m}) match as much as possible and back off until the whole pattern succeeds. Add a question mark to make them lazy and match as little as possible.
  • String.matchAll requires the g flag. String.replaceAll requires either a string or a regex with the g flag.
  • Inside a character class, most metacharacters lose their special meaning. Only -, ], \\, and ^ (at the start) need escaping.

How to use

  1. Search by token (like \d, *, ?, ^), by topic (like lookahead, anchor, quantifier), or by use case (email, url, uuid) to find the right entry.
  2. Use the section filter chips to narrow the page to anchors, character classes, quantifiers, groups, lookaround, flags, Unicode, or common patterns.
  3. Edit the test input on any entry to see the highlighted matches update live, so you can confirm the rule fires the way you need before copying it.
  4. Use Copy token to grab the raw syntax (like \b or (?:...)) or Copy regex to grab the full /pattern/flags literal for that example.
  5. Open the Quick playground at the top to test any pattern and flag combination, with copy buttons for both regex literal and new RegExp constructor forms.

About this tool

Regex Cheat Sheet is a searchable JavaScript regular expression reference where every entry is live. The page is organized into the categories you actually look up: anchors (^, $, \b), character classes ([abc], [^abc], ranges, .), shorthand classes (\d, \w, \s and their negations), quantifiers (?, *, +, {n}, {n,m}, lazy forms), groups and references (capturing, non-capturing, named, numbered and named backreferences), alternation, lookaround (positive and negative lookahead and lookbehind), escapes and special characters, flags (g, i, m, s, u, y), Unicode property escapes (\p{L}, \p{N}, scripts), and a final block of common patterns ready to copy: simple email, URL, hex color, ISO 8601 date, IPv4 shape, canonical UUID, slug-safe identifier, E.164 phone number. Every entry shows the token, what it does, a worked example, and a small editable test box where the matches highlight as you type, so you can confirm the rule fires the way you expect before pasting it into your code. A quick playground sits at the top of the page for trying any pattern with full flag control and copy buttons for both the regex literal and the new RegExp constructor form. A search box and section filters help you jump straight to the token you need. Built for developers working in JavaScript, TypeScript, Node.js, and browser code, but most of the syntax also applies to Python, PHP, Java, and Go with minor differences. Nothing is uploaded; pattern matching runs in your browser through the native RegExp engine.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools