Skip to content
Tridev Innovation

Developer Tools

Regex Tester & Cheatsheet

Write or paste a regular expression, choose your flags, and test it against real text with live match highlighting, plus capture groups, a plain-language pattern breakdown, and a quick-reference cheatsheet. Built for developers debugging a pattern, writing validation logic, or just relearning regex syntax. Everything runs locally in your browser; nothing you type here is ever uploaded.

Flags
Valid pattern
Matching…

No matches found

Common regex examples

Load a ready-made pattern to see it in action. These cover common shapes developers reach for — treat them as a practical starting point, not a guarantee of perfect real-world validation.

Pattern breakdown

A plain-language explanation of the recognizable constructs in your current pattern.

  • (Capturing group: groups a sub-pattern and captures the matched text as a numbered group.
  • [\w.+-]Character class: matches any one character listed inside.
  • +Quantifier: the previous token repeats one or more times. Greedy: matches as many characters as possible.
  • (Capturing group: groups a sub-pattern and captures the matched text as a numbered group.
  • [\w-]Character class: matches any one character listed inside.
  • +Quantifier: the previous token repeats one or more times. Greedy: matches as many characters as possible.
  • \.Escaped character: matches a literal "." rather than any special meaning it might otherwise have.
  • [\w.-]Character class: matches any one character listed inside.
  • +Quantifier: the previous token repeats one or more times. Greedy: matches as many characters as possible.

This breakdown recognizes common constructs but isn't a full parser. Some parts of complex patterns (nested groups, unusual escapes) may not appear above even though they still work when matching.

Regex cheatsheet

A quick reference for JavaScript regex syntax. Click Try on any entry to drop it straight into the pattern above.

Character classes

  • .

    Any character except line breaks

    gr.y matches gray, grey

  • \d

    Any digit (0-9)

    \d{3} matches 415

  • \D

    Any non-digit character

  • \w

    Word character: letters, digits, underscore

    \w+ matches hello_1

  • \W

    Non-word character

  • \s

    Whitespace: space, tab, newline

    a\sb matches "a b"

  • \S

    Non-whitespace character

  • [abc]

    Any one of a, b, or c

  • [^abc]

    Any character except a, b, or c

  • [a-z]

    Any character in the range a to z

Quantifiers

  • *

    Zero or more times

    ab*c matches ac, abc, abbc

  • +

    One or more times

    ab+c matches abc, abbc (not ac)

  • ?

    Zero or one time (optional)

    colou?r matches color, colour

  • {n}

    Exactly n times

    \d{4} matches 2026

  • {n,}

    n or more times

    \d{2,} matches 42, 4200

  • {n,m}

    Between n and m times

    \d{2,4} matches 42, 4200

Anchors

  • ^

    Start of the string (or line, with m flag)

    ^Hello matches only at the start

  • $

    End of the string (or line, with m flag)

    end$ matches only at the end

  • \b

    Word boundary

    \bcat\b matches "cat" not "category"

  • \B

    Not a word boundary

Groups & alternation

  • (abc)

    Capturing group: remembers the matched text

  • (?:abc)

    Non-capturing group: groups without remembering

  • (?<name>abc)

    Named capturing group

  • a|b

    Matches a or b

Lookarounds

  • (?=abc)

    Positive lookahead: followed by abc

  • (?!abc)

    Negative lookahead: not followed by abc

  • (?<=abc)

    Positive lookbehind: preceded by abc

  • (?<!abc)

    Negative lookbehind: not preceded by abc

Flags

  • g

    Global: find all matches

  • i

    Ignore case

  • m

    Multiline: ^ and $ match per line

  • s

    Dot All: . also matches newlines

  • u

    Unicode mode

  • y

    Sticky: match only at lastIndex

What is a regular expression?

A regular expression (regex, or regexp) is a compact syntax for describing patterns in text. Instead of searching for one exact string, a regex describes a shape: "a digit followed by three letters," "anything between two quotes," or "a word repeated twice in a row." The regex engine then finds every piece of text that matches that shape. It's built into nearly every programming language, text editor, and command-line tool, which is why the same core syntax (with small dialect differences) shows up everywhere from JavaScript to grep to your IDE's find-and-replace.

Developers reach for regex because it turns pattern matching from a manual, error-prone loop of string checks into a single declarative expression. A pattern is built from literal characters (which match themselves), character classes like \d or [a-z] (which match a category of characters), quantifiers like + or {2,4} (which control how many times something repeats), and structural pieces like groups and alternation that let you combine smaller patterns into bigger ones. The regex engine scans the input text and reports every position where the pattern's rules are satisfied.

In day-to-day work, regex shows up in form validation (does this look like a phone number?), log and data parsing (pull every IP address out of this file), search-and-replace across a codebase, URL routing, extracting structured fields from unstructured text, and cleaning up messy data before it goes into a pipeline. It's not always the right tool (see regex vs. string methods below), but for genuine pattern matching, nothing else is as concise.

How to use the Regex Tester

  1. Enter a pattern in the regex field, with or without surrounding /slashes/. Click Load example if you want to start from a working pattern.
  2. Select flags using the toggle buttons: g to find every match instead of just the first, i for case-insensitive matching, and so on.
  3. Enter or paste realistic test text in the Test text box.
  4. Review the highlighted matches directly in your text, updated live as you type.
  5. Inspect each match's position, and expand into its numbered and named capture groups, in the Match results panel.
  6. Refine the pattern based on what did or didn't match, using the pattern breakdown and cheatsheet below to check the syntax you're using.

Understanding regex syntax

Character classes match a category of characters at one position: \d for digits, \w for word characters, \s for whitespace, or a custom set like [aeiou].

Quantifiers control repetition: * (zero or more), + (one or more), ? (optional), and {n,m} (a specific range) all attach to the token immediately before them.

Anchors match a position rather than a character. ^ and $ pin a match to the start or end of the string (or line, with the m flag), and \b matches a word boundary.

Groups like (abc) capture matched text for later use, (?:abc) groups without capturing, and (?<name>abc) captures with a readable name instead of a number. Alternation (a|b) matches either side of the pipe.

Lookarounds, (?=...), (?!...), (?<=...), and (?<!...), assert that something does or doesn't appear before or after the current position, without including it in the match itself. All four are supported in modern JavaScript engines.

Flags change how the whole pattern behaves: g finds all matches, i ignores case, m makes ^/$ match per line, s lets . match newlines, u switches to Unicode-aware mode, and y matches only at the exact current position.

Common regex mistakes

Most regex bugs come from a small set of recurring misunderstandings. Here are the ones worth double-checking first:

Forgetting to escape special characters
3.14

A bare "." matches any character, not just a literal dot. It happens to match "3.14" but also "3x14". Escape it as \. when you mean a literal period.

Using * when + is required
\d*

\d* matches zero or more digits, so it happily matches an empty string too. If you need "at least one digit," use \d+ instead.

Anchoring only one end of the pattern
^\d{5}

Without a trailing $, ^\d{5} matches the first 5 digits of "123456" and stops. It doesn't require the whole string to be exactly 5 digits. Add $ (or use test text with the m flag in mind) when the full string must match.

Forgetting the g flag
/\d+/

Without the g flag, JavaScript's regex engine stops after the first match. That's useful sometimes, but it's a common source of "why did it only find one result" confusion when scanning a whole document.

Greedy vs. lazy matching surprises
<.+>

Quantifiers are greedy by default: <.+> against "<b>bold</b>" matches the entire string from the first < to the last >, not just "<b>". Use the lazy version, <.+?>, to stop at the first >.

Misunderstanding \d, \w, and \s
\w+@\w+

\w only covers letters, digits, and underscore. It doesn't include dots, dashes, or plus signs, so \w+@\w+ misses plenty of real email addresses and domains. Character classes need to match what your data actually looks like, not just the common case.

Assuming regex can fully validate complex formats
^[\w.-]+@[\w.-]+\.\w+$

A pattern like this rejects some technically valid email addresses and accepts some invalid ones: real email validation (and similarly, full postal address or phone number validation) usually needs more than a single regex to be reliable.

Regex vs. string methods

Regex is powerful, but it's not always the clearest or fastest option. When the check is simple, plain string methods are usually more readable and often faster to run:

  • includes(): checking whether a fixed substring appears anywhere, e.g. url.includes("https://"), instead of a regex just to test for a literal string.
  • startsWith() / endsWith() : checking a fixed prefix or suffix, e.g. a filename ending in .pdf, is clearer than /\.pdf$/.
  • split(): breaking text on a fixed, simple delimiter like a comma doesn't need regex at all (though split() does also accept one for variable-width delimiters).
  • replace(): replacing one fixed substring is simpler without regex; reach for a regex replacement once the thing you're replacing varies (whitespace runs, digits, optional parts).

As a rule of thumb: if you can describe the check in one sentence without the word "pattern," a string method probably expresses it more clearly. Reach for regex once you're matching variable text, multiple alternatives, repetition, or need to extract pieces of a larger string.

Frequently asked questions

Need something more custom than a free tool?

If a ready-made utility won't cut it, our engineering team builds custom software, APIs, and data pipelines too.