Regex Tester

Text

Test JavaScript regular expressions with flags like g, i, m, s and u plus capture groups, listing every match and named group as you type. All hits listed.

//
3 matches
Common:
Test text
Highlighted
Contact alice@example.com or bob@test.org for details, or admin@site.io
Matches
#0alice@example.com@ 8–25
$1alice
$2example.com
#1bob@test.org@ 29–41
$1bob
$2test.org
#2admin@site.io@ 58–71
$1admin
$2site.io

About Regex Tester

The worst thing about regular expressions is that they look right until they fail on a specific input. A form validator lets through what it should block, a log extractor misses a variant spelling, a replace touches what it should have left alone. A regex tester converts "I think this is correct" into "I can see exactly where it matches", replacing trial and error with highlighted matches and captured groups. It works by handing your expression to the browser's native regex engine and showing every match and capture group live. Because it is the same engine you use in code, what you see matches runtime behaviour, which is more reliable than tools running a different language's implementation, though it still cannot replace knowing the differences in your target engine. Practical notes: Turn on the global flag first, or only the first match is highlighted and you may wrongly conclude the pattern matches once. Use named groups when inspecting captures so results are labelled rather than counted. Your test set must include counter-examples: samples that pass prove nothing about over-permissiveness, so prepare at least three groups, namely "should match", "should not match" and edge cases such as the empty string, very long input and embedded newlines. As for tuning, get correctness first and only then think about performance. Limits: Engines differ substantially and syntax is not portable: whether dot matches newlines, whether backtracking and possessive quantifiers exist, and what counts as a word boundary all vary, so an expression verified in one language must be re-verified in another. The danger to watch for is catastrophic backtracking, where nested quantifiers such as (a+)+b backtrack exponentially on long non-matching input and a few hundred characters can pin a CPU core. Avoid that shape in production or replace it with explicit character classes. Regular expressions are also the wrong tool for nested structures such as HTML or JSON, which need a real parser. Data and privacy: people test regexes by pasting real logs, spreadsheets with phone numbers, or user input samples, and anything uploaded may be retained. This tool runs the built-in engine locally, the input never leaves the device, and it keeps working offline. A short checklist on engine differences and maintainability. In JavaScript, dot excludes newlines unless the s flag is set; Python needs re.S at compile time; Java likewise does not cross lines by default but offers an inline DOTALL switch. Lookarounds work in most modern engines, yet variable-length lookbehind support is inconsistent and only some engines allow it. Named groups and backreferences use different syntaxes across JavaScript, Python and .NET, so (?P<name>) and (?<name>) are not interchangeable. On maintainability, any pattern longer than a screen should be assembled from named fragments joined as strings, with a comment explaining what each part matches. Leaving an unreadable expression in business code means the maintenance cost climbs with every staff change, and replacing it with a small parsing function is often the clearer choice. Finally, separate regular expressions from globs: patterns such as *.log or src/**/*.ts match filenames or paths only, are deliberately simple, do not transfer to text search, and carry no backtracking risk. Carrying glob intuition into regex, for instance assuming * alone means "any number of characters", is one of the most common beginner mistakes. For one-off data cleanup, exporting a sample and validating it with a local script is usually faster and more reproducible than iterating inside a web tool.

How It Works Internally

A regex engine tries to match by advancing left to right and backtracking. Backtracking is where the power comes from — it lets a+b match any number of a — and also where performance problems come from: nested quantifiers such as (a+)+b produce exponentially many attempts on long non-matching input. Greedy versus lazy changes how much is matched, never whether a match exists.

Global match with groups
Input/(\d{4})-(\d{2})/g against "2026-10 and 2027-03"
OutputTwo matches, groups ("2026","10") and ("2027","03")

Measured on This Page

Counts correct\d+ finds 3 matches in a1b22c333, the email pattern finds 2 in x@y.com z@w.com, and ^a.c$ finds 1 in abc — all identical to Python re
Capture groups(\w+)@(\w+)\.com exposes both groups, enough to pull the local part and domain apart
Flagsg, i, m, s and u toggle individually and results recompute immediately
Error handlingAn invalid pattern such as an unclosed parenthesis reports a compile error instead of quietly returning nothing

Regex tools are prone to results that look right while the boundary is wrong (all 3 samples agreed here), so against a standard library rather than eyeballing highlights. Match counts agree with Python re across global matching, capture groups and anchors. Three things worth knowing: the g flag and test() have a state trap in JS — repeated test() calls on one RegExp object miss matches because lastIndex persists, and this page sidesteps it by building a fresh object per run; catastrophic backtracking hits patterns like (a+)+b on long input, and there is no timeout here, so avoid nested quantifiers on big text; and \d stays ASCII-only even under the u flag, unlike some other languages.

How this was measured: Three expressions (a global \d+, an email pattern with capture groups, and the anchored ^a.c$) were run against fixed text, and the match counts shown by the page were compared with counts computed by Python re. · Measured 2026-10-31

How to Use

  1. Open the Regex Tester tool
  2. Enter your regular expression in the pattern field
  3. Enter test text in the test text area
  4. View highlighted matches and the match list
  5. Use Replace mode for text substitution

Use Cases

  • Form validation — Debug email, phone, URL, and password-strength validation patterns.
  • Log extraction — Pull timestamps, error codes, IP addresses, and other fields out of large log files.
  • Batch replacement — Iterate on a regex here, then apply it via your editor's find-and-replace across the codebase.
  • Web scraping cleanup — Extract structured data — prices, titles, ratings — from scraped HTML.
  • Learning regex syntax — Tweak a pattern and see live highlights — much faster than reading docs.
  • Search and replace preview — Test regex substitution patterns with capture group references ($1, $2) before running them across your codebase.
  • Data validation pipelines — Build and debug multi-step validation patterns for CSV rows, log entries, or user-submitted form data.

FAQ

Which regex flavor does this tool use?

JavaScript / ECMAScript flavor (a subset of PCRE). Notable gaps: no \g back-references, no atomic groups (?>), no balancing groups. Python's re module is mostly compatible.

Why doesn't my regex match?

Most common reasons: (1) missing g flag matches only the first hit; (2) unescaped special chars . * ? +; (3) using ^/$ on multiline text without the m flag.

Can regex have performance issues?

Yes. Nested quantifiers like (a+)+ on a non-matching input can trigger catastrophic backtracking and freeze a page. This tool uses the native engine, which times out and aborts.

How do I test grep or sed regex?

They use BRE/ERE flavors that escape some metacharacters differently (e.g. \(\) for groups). This tool is not fully compatible — for complex shell regex, test directly in the terminal.

How do I remember common patterns?

See our Regex Cheatsheet tool, which collects ready-made patterns for email, URL, IP, credit-card, and more.

Why doesn't ? match the character I expected?

A question mark has two meanings in regex: right after a character it means the preceding character appears 0 or 1 times (colou?r matches both color and colour), while after a quantifier * + ? it makes the match lazy (non-greedy). If you actually want a whole optional fragment, a bare ? often scopes incorrectly. Instead, wrap the fragment you want optional inside a group first, e.g. (https?://)?, and use a non-capturing group (?:...)? if you don't need to capture it. Put it outside the parentheses and test again so it only affects the whole group, not the single adjacent character.

Why doesn't . match newlines?

By default the dot . matches any character except a line terminator, so on multiline text it stops at the end of each line. Fix it three ways: add the s flag (single-line mode) so . also matches newlines; use [\s\S] to cover both whitespace and non-whitespace; or write [^\n] explicitly (which still excludes newlines). For matching an entire block across lines, prefer the s flag with a lazy .*?; paste the real multiline log into the test area first to confirm the result.

The tester result differs from my production code?

Align two things: engine differences (JS vs PCRE on lookbehind and named groups) and flags — the g flag makes lastIndex affect successive matches. Set the tester's flags to match production and re-run with identical input.