Like ToolFern? Prefer us as your source on Google →

Regex Tester

Write a regular expression, toggle the flags, and watch it match your test text live, with a running match count, every matched substring and any capture groups. Get aplain-English explanation of what your pattern does, preview a find and replace, and check the built-in cheatsheet whenever you forget the syntax. Free and instant.

Common patterns

Click one to fill the field above with a ready-to-use pattern, then tweak it if you need to.

What this pattern does

Enter a pattern above to see a plain-English, token-by-token breakdown.

0
Matches
Matches

Enter a pattern above to start matching.

Regex quick reference

A static cheatsheet of common syntax. It does not react to the pattern above, use the explanation panel for that.

AnchorMeaning
^Start of the string (start of each line with the m flag)
$End of the string (end of each line with the m flag)
\bA word boundary
\BNot a word boundary
Character classMeaning
.Any character (except line breaks, unless the s flag is set)
\d / \DA digit / anything that is not a digit
\w / \WA word character (letter, digit, underscore) / anything that is not
\s / \SWhitespace / anything that is not whitespace
[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
QuantifierMeaning
*Zero or more times
+One or more times
?Zero or one time (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*? +? ??Lazy versions, match as little as possible instead of as much as possible
Groups and alternationMeaning
(...)Capturing group
(?:...)Non-capturing group
(?<name>...)Named capturing group
a|bMatches a or b
(?=...)Positive lookahead, must be followed by
(?!...)Negative lookahead, must not be followed by
(?<=...)Positive lookbehind, must be preceded by
(?<!...)Negative lookbehind, must not be preceded by
FlagMeaning
gGlobal, find every match instead of just the first
iIgnore case
mMultiline, ^ and $ match at every line
sDotall, . matches line breaks too
uUnicode mode, treats the pattern as full Unicode code points

This tool's checkboxes cover g, i, m and s. The u flag is listed for reference and is not offered as a checkbox here.

Example patterns below are illustrative only, not production-ready validation. Real email and URL validation is notoriously complex, these short patterns will reject some valid input and accept some invalid input in edge cases. Use a dedicated library or a server-side check for anything that actually matters.

Looks likeIllustrative pattern
Email-ish^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$
URL-ish^https?:\/\/[\w.-]+\.[a-zA-Z]{2,}(\/\S*)?$
US phone-ish^\(?\d{3}\)?[\s-]?\d{3}-\d{4}$

How to use this regex tester

  1. Type your pattern in the top field, just the body, no surrounding slashes. For example, \b\w+@\w+\.\w+\b to find simple email-like strings.
  2. Pick your flags with the checkboxes: g finds every match (not just the first), i ignores letter case, m makes ^ and $ match at every line, and s lets . match newlines too.
  3. Read the What this pattern does panel for a plain-English, token-by-token breakdown of your pattern, anchors, character classes, quantifiers, groups and lookarounds are all called out as you type.
  4. Paste your test text into the box below. Matching runs instantly on every keystroke, no button to press.
  5. In Match mode, the Matches counter shows how many were found, and each match is listed with its position and any capture groups.
  6. Switch to Replace mode to try a substitution: type a replacement using $1, $2… for capture groups or $<name> for named groups, and the result preview updates live.
  7. Copy the matches or the replaced result to your clipboard, or Clear to start fresh.
  8. Stuck on syntax? The regex quick reference below the tool is a static cheatsheet of anchors, character classes, quantifiers, groups and flags.

A quick refresher on regular expressions

A regular expression (regex) is a tiny pattern language for describing text. Plain characters match themselves, while special tokens describe shapes: \d is any digit, \w a word character, \s whitespace, and . any character. Quantifiers say how many, * (zero or more), + (one or more), ? (optional) and {2,4} (a range). Brackets like [a-z] define a character set, and parentheses (.) create a capture group so you can pull out just the part you care about.

This tool uses the JavaScript regex engine built into your browser, so what you see here is exactly what String.prototype.match and RegExp.prototype.exec will do in your own JavaScript or Node.js code, including how capture groups, named groups (?<year>\d{4}) and the global flag behave. That makes it a faithful scratchpad for front-end and back-end developers alike.

Capture groups and match positions

Every result shows the full match plus its index (the zero-based character position where it starts). If your pattern contains parentheses, each capture group is listed beneath the match in order, and named groups are shown by name. A group that did not participate in the match appears as undefined, useful for spotting optional branches that did or did not fire. With the g flag off, only the first match is returned, mirroring how a non-global exec behaves.

Plain-English explanation, replace mode and the cheatsheet

The What this pattern does panel walks your pattern token by token and explains each piece in plain English, anchors, character classes, quantifiers (including whether they are greedy or lazy), groups, alternation and lookaround are all called out as you type. It is a solid breakdown of common syntax, not a full regex parser, so anything it does not recognize is labelled honestly as an unrecognized token instead of guessed at.

Switch to Replace mode to preview a substitution. Type a replacement using $1, $2… to reference capture groups or $<name> for named groups, exactly like JavaScript's ownString.prototype.replace, because that is exactly what runs under the hood. The result preview updates live as you edit the pattern, flags, replacement or test text.

The regex quick reference underneath the tool is a static cheatsheet, always visible, covering the same anchors, character classes, quantifiers, groups and flags in one place. The illustrative email, URL and phone patterns in it are simplified examples, not production-ready validation regex.

Frequently asked questions

Do I include the slashes, like /abc/g?

No. Type only the pattern body (abc) in the pattern field and set the flags with the checkboxes. Adding literal slashes would make them part of the pattern.

My pattern matches forever or is slow, why?

Some patterns (often nested quantifiers like (a+)+) can cause catastrophic backtracking on certain inputs. Simplify the pattern or anchor it. Zero-width matches are handled safely here so the tool will not loop infinitely.

Does it support named capture groups and lookbehind?

Yes, it runs the modern browser regex engine, so named groups (?<name>…), lookahead and lookbehind all work in any up-to-date browser.

How does the plain-English explanation work?

A hand-written tokenizer walks your pattern and matches recognizable constructs (anchors, character classes, quantifiers, groups, common escapes, lookaround) to a description. It covers common, well-known syntax rather than every possible construct, unusual or obscure tokens are labelled as unrecognized instead of misdescribed.

Is the replace preview a real JavaScript replace?

Yes. It calls your test text's own .replace() with the RegExp built from your pattern and flags, and your replacement string, so $1, $2 and $<name> behave exactly as they would in your own code.

Are the cheatsheet's example patterns safe to use in production?

Treat them as illustrative only. Real email and URL validation is notoriously hard to get exactly right, these short examples will reject some valid input and accept some invalid input in edge cases. For anything that matters, use a dedicated validation library or a server-side check.

Found this useful? Share it