SimplyCalculated.org

Regex Tester

Test any JavaScript regular expression against your own text with live highlighting, match counts, and capture groups — entirely in your browser.

100% private: everything is processed in your browser's memory — nothing you enter is uploaded to a server, logged, or stored.

Regex Tester

/ /
Matches

What Is a Regular Expression?

A regular expression — regex for short — is a compact pattern language for describing text. Where a plain search looks for an exact string, a regex describes the shape of a string: "five to eight digits", "a word character followed by an @", "a date in YYYY-MM-DD form". That power makes regex the backbone of text processing in every programming language, most editors (VS Code, Sublime, Vim), and command-line tools like grep and sed. Learning to read and write regex pays off across your entire toolchain.

The core building blocks are: literal characters (a matches "a"), metacharacters with special meaning (. matches any character, * and + are quantifiers), character classes that match one of a set ([\d._-] matches any digit, dot, underscore, or hyphen), anchors that fix a position (^ start, $ end), and groups that capture or group parts of a match. A pattern like ^[A-Z]\d{3}$ matches a single uppercase letter followed by exactly three digits and nothing else.

The Core Syntax, Explained

Construct Meaning Example
\dAny digit (0–9)\d{3}
\wWord character (letter, digit, underscore)\w+
\sWhitespace (space, tab, newline)\s+
.Any character except newlinea.c
* + ?Zero+, one+, zero-or-one of the previouscolou?r
{n,m}Between n and m repetitions\d{2,4}
[abc]One of the characters in the set[aeiou]
^ $Start / end of text (or line with m)^TODO
(…)Capture group(ab)+
a|bAlternation (a or b)cat|dog
\bWord boundary\bcat\b

Step-by-Step Example: Extracting Email Addresses

Let's say you have a block of support tickets and you want to pull every email address out of it. Paste the text into the tester and build the pattern up step by step.

  1. Start simple: the pattern \S+@\S+ matches any run of non-space characters around an @ — a first pass that catches most addresses.
  2. Tighten the local part: [\w.+-]+@\S+ restricts the part before @ to word characters, dots, pluses, and hyphens, which excludes trailing punctuation.
  3. Capture the pieces: ([\w.+-]+)@([\w.-]+) wraps each half in a capture group so you can see the username and domain separately.
  4. Check the highlights: the output marks each match, and the count in the summary tells you whether you caught them all or over-matched.

Try the final pattern against a paragraph containing a few emails and notice how the highlights track exactly what you asked for — and how quickly you can iterate when they don't.

Common Patterns Reference

What It Matches Pattern
US phone number\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
Date (YYYY-MM-DD)\d{4}-\d{2}-\d{2}
Hex color code#[0-9a-fA-F]{6}\b
Whole number^-?\d+$
Decimal number-?\d+(\.\d+)?
Whitespace runs[ \t]+
Trailing spaces[ \t]+$

Troubleshooting & Practical Tips

Escape Metacharacters

The characters . * + ? ( ) [ ] { } ^ $ | \ all have special meaning. To match them literally, prefix with a backslash: a literal dot is \., a literal asterisk is \*, and a literal backslash is \\. Forgetting this is the single most common regex bug — "I searched for 3.5 and it matched 3x5".

Greedy vs. Lazy Quantifiers

Quantifiers are greedy by default: .+ matches as much as it can, so <.+> against "a <b> c <d>" matches the whole "<b> c <d>" rather than each tag. Adding a ? makes it lazy: <.+?> matches each tag individually. When your highlights look "too big", laziness is usually the fix.

Use Anchors to Avoid Partial Matches

A pattern like \d{3} matches the first three digits of "12345". When you want a whole thing and nothing more, anchor it — ^\d{3}$ for the entire text, or \b\d{3}\b for a three-digit token surrounded by word boundaries.

Common Mistakes to Avoid

  • Forgetting to escape dots, pluses, and other metacharacters.
  • Over-escaping in the tester — a slash inside the pattern field needs no backslash.
  • Using $ to mean "end of line" without the m flag.
  • Testing on tiny sample text and assuming it generalizes to real input.
  • Ignoring capture groups when all you need is the matched text.

Frequently Asked Questions

What is a regular expression?
A regular expression (regex) is a pattern that describes a set of strings. Instead of searching for one exact word, you describe the shape of what you want to find — for example, "any sequence of digits" is written d+, and "an email-like pattern" can be written [w.+-]+@[w-]+.[w.-]+. Regex is built into every programming language and most text editors and command-line tools, and it's one of the most useful skills a developer or power user can have.
Which regex syntax does this tester use?
This tester uses the JavaScript (ECMAScript) regular expression engine — the same one in Node.js and every browser. It supports character classes like d, w, and s, quantifiers like *, +, and {2,3}, groups and alternation like (ab|cd), anchors ^ and $, lookaheads and lookbehinds, and the standard flags g (global), i (case-insensitive), m (multiline), s (dotall), and u (unicode). If you're writing regex for another language, most of the syntax carries over, but check that language's engine for differences.
What do the flags g, i, m, s, and u mean?
g (global) finds every match instead of stopping at the first — our tester always searches globally. i makes matching case-insensitive, so "hello" matches "HELLO". m makes ^ and $ match at line starts and ends instead of just the start and end of the whole text. s (dotall) makes the dot match newlines too. u (unicode) enables proper handling of unicode code points, so emoji and non-Latin scripts are matched as single characters.
Why is my regex not matching when it works elsewhere?
The most common causes: you forgot to escape a special character (a literal dot must be . not .), you're using a syntax your engine doesn't support (like a lookbehind in an older browser), or you're mixing up anchors — ^ matches the start of the text (or line with m), and $ matches the end. It's also easy to over-escape: in JavaScript you don't need to escape the / character inside a regex when you're not using the literal /.../ syntax.
How do I test a regex that contains a forward slash?
In our tester, just type the slash directly into the pattern field — since you're typing the raw pattern rather than the /pattern/ literal syntax, a slash needs no escaping at all. If you're copying the pattern into JavaScript code, you'll need to escape it as / when using the literal syntax, or better, use the RegExp constructor with a string (where you escape only backslashes).
Can I use capture groups with this tester?
Yes. Parenthesized parts of your pattern become capture groups, and each match's group values are available in the output. Groups are numbered from left to right starting at 1, and named groups like (?<name>...) are supported too. This is especially useful when you're building a find-and-replace or extracting structured data like dates or URLs.
Is my regex or test text sent to a server?
No. Everything runs entirely in your browser — the pattern is compiled and matched locally with JavaScript's own RegExp engine, and nothing you type leaves your device. This makes the tester safe to use with sensitive data like API keys, internal logs, or personal information that you'd never want to paste into an online tool that uploads it.

Formula last verified August 22, 2026 against our published methodology .