How to Test Regex Patterns
Test regex in your browser. Enter a pattern and test text, toggle flags, inspect matches and capture groups, and preview replacements locally.
Regular expressions are powerful precisely because they’re compact, but that same compactness makes them easy to get subtly wrong. A pattern that looks correct can match too much, too little, or nothing at all, and the only reliable way to know is to run it against real text. The Regex Tester runs a JavaScript regular expression in your browser, shows every match with its capture groups, and previews replacements — all without uploading your text.
TL;DR
You can develop and verify a regex against real input, entirely locally.
- See matches and groups — every match lists its text, index range, and capture groups (including named groups).
- Preview replacements — type a replacement and see the changed output instantly, with no match shown when nothing changes.
- All seven JS flags — toggle g, i, m, s, u, y, or d and watch the result update.
What regex is
A regular expression is a pattern that describes a set of strings. It’s the standard tool for searching, validating, extracting, and replacing text, and it’s built into every programming language. In JavaScript, a regex is a RegExp object, and you write it either as a literal (/\d+/g) or by constructing one (new RegExp("\\d+", "g")).
The common jobs regex does:
- Validation — “does this string look like an email, a date, a phone number?”
- Extraction — “pull every URL, every number, every quoted phrase out of this text.”
- Replacement — “swap every placeholder with a real value,” or “normalize all whitespace.”
Because regex is terse and symbolic, a single misplaced character changes the meaning. Testing against representative input is how you turn “I think it works” into “it works.”
The parts of a regex pattern
A pattern is built from a few building blocks. Knowing them by name makes patterns readable:
- Literals — ordinary characters that match themselves.
catmatches the lettersc,a,tin order. - Character classes — a set of allowed characters in brackets.
[a-z]matches any lowercase letter;\dis shorthand for[0-9],\wfor word characters,.for (almost) any character. - Quantifiers — how many times the previous thing repeats.
*is zero or more,+is one or more,?is zero or one, and{n}or{n,m}is an exact or bounded count. - Anchors — position, not characters.
^matches the start of the string (or line, with themflag),$the end. - Groups — parentheses
(...)capture part of a match so you can refer to it later. Named groups(?<year>\d{4})give a capture a readable name. - Alternation —
cat|dogmatches eithercatordog.
Composing these is how patterns are written, and seeing them applied to text is how they’re verified.
Flags
Flags modify how the whole pattern behaves, and they’re appended after the closing slash (for example /x/gi). The tester exposes all seven JavaScript flags as toggles:
- g (Global) — find all matches, not just the first. Without
g, matching stops after the first hit. - i (Ignore case) — make the match case-insensitive, so
[a-z]also matches uppercase. - m (Multiline) — let
^and$match the start and end of each line, not just the whole string. - s (Dot all) — let
.match newline characters too, which it normally does not. - u (Unicode) — treat the pattern as Unicode code points, essential for emojis and non-ASCII scripts.
- y (Sticky) — match only at
lastIndex, anchoring each search to an exact position. - d (Indices) — expose the start and end indices of each capture group, in addition to their values.
Most everyday work needs only g and i; the rest solve specific cases that come up with multiline text, Unicode, or advanced scanning.
Step-by-step: test a pattern
Open the Regex Tester and work through this flow.
- Enter your Pattern in the Pattern field. Type it without the surrounding slashes and without flags — the tool builds the literal for you.
- Paste your Test text into the test-text field. This is the haystack your pattern searches.
- Toggle the Flags you need — g, i, m, s, u, y, or d. The result updates as you toggle.
- Check the Matches tab. Each match shows the matched text, its index range, and any capture groups (named groups appear with their names). If nothing matches, you’ll see “No matches”.
- Switch to the Replace tab. Type a Replacement string (you can reference capture groups like
$1or$<name>). The tool runstext.replace(regex, replacement)and shows the changed output, or tells you when nothing changed. - Copy or reset. Use Copy regex to grab the regex literal, Copy summary for the match list, Copy replacement for the replaced output, or Reset to clear everything.
If you’re not sure where to start, the Sample dropdown loads a ready-made pattern and text for Date, Email, URL, or Words, so you can see a working example immediately.
Limits and JavaScript-specific notes
A few honest constraints, so the tool matches what you expect:
- JavaScript engine only. The tool runs
new RegExp(pattern, flags)in your browser, so it reflects the JavaScript regex engine — not PCRE, Python, or Java. Patterns written for other engines may behave differently, and the tool won’t “explain” a pattern for you. - Bounded sizes. The pattern is capped at 500 characters and the test text at 20,000. Exceed either and the tool flags the problem rather than running.
- Matches are capped at 200. When a pattern matches more than 200 times, the tool shows the first 200 with a “Showing first 200 matches.” notice. For verification that’s plenty; for counting huge inputs, narrow your pattern.
- Lookbehind varies by engine and age. JavaScript lookbehind (
(?<=...)) is supported in modern browsers but was absent in older engines and differs from PCRE. If a lookbehind fails, that’s usually why.
FAQ
Does it support PCRE?
No. The tool uses the JavaScript RegExp engine (new RegExp(pattern, flags)), which has its own syntax and feature set and is not PCRE-compatible. PCRE-only features — such as recursive patterns or certain POSIX classes — won’t work here. Write patterns for the JavaScript engine, or convert PCRE patterns before testing them.
What are capture groups?
Parentheses in a pattern ( ... ) create a capture group that remembers the part of the text it matched, so you can refer to it later — by number ($1, $2) in a replacement, or by name if you wrote a named group (?<name> ...). The Matches tab shows each group’s value (and name, when present), which is how you confirm the pattern is capturing what you intended.
How do I replace text?
Switch to the Replace tab and type a Replacement. The tool runs text.replace(regex, replacement) with your current flags and shows the result; you can reference capture groups with $1, $2, … or named groups with $<name>. If the global flag g is off, only the first match is replaced. When nothing changes, the tool says so plainly.
Why only 200 matches?
For safety and speed. A pattern can match thousands of times in a large document, and rendering every match would slow the page to a crawl. The cap of 200 is enough to verify that a pattern matches what you think it does; if you need the full count, make the pattern more specific or test against a smaller excerpt.

Start with this tool
Get started