TextNew

JavaScript Regex Tester with Capture Groups

Test regular expressions with real-time matching

100% client-side — your data never leaves your browserNo data stored or uploadedFree for lifetime · No signup
//gi

What is a regex tester?

A regex tester lets you write a regular expression and see immediately what it matches against a sample string — every match is highlighted in place and listed with its index and capture groups, updating on each keystroke. That instant feedback loop is the difference between confidently shipping a pattern and discovering in production that it matched too much or too little.

This tester uses JavaScript's native RegExp engine, so what matches here is exactly what will match in Node.js and the browser. Your pattern and test string never leave your machine.

When to use it

Use it while writing validation (emails, slugs, version strings), extracting values from logs or scraped text, building search-and-replace expressions for your editor, or debugging a pattern that behaves differently than you expect. The flag toggles cover the four you'll reach for most: g finds all matches instead of just the first, i ignores case, m makes ^ and $ match at line boundaries, and s lets . match newlines.

Capture groups are shown separately for each match, which makes it easy to check that your parentheses are grabbing the piece you actually want — the most common source of off-by-one regex bugs.

Example

To pull semantic versions out of a changelog, try the pattern (\d+)\.(\d+)\.(\d+) with flags gi against a few lines of release notes. Each match lists three groups — major, minor, patch. When it works, use "Copy link to this result" to share the pattern with your test string embedded in the URL, so a teammate opens exactly what you're looking at.

Regex differences: Python, Java, C# and PHP vs JavaScript

Most syntax — character classes, quantifiers, groups, anchors, \d \w \s — is shared, so the bulk of patterns move between languages unchanged. The differences cluster in a few places.

Named groups: JavaScript, Java, C# and PHP write (?<year>\d{4}) and refer back with \k<year>. Python's re module uses (?P<year>\d{4}) and (?P=year); paste a Python pattern here and the P is a syntax error, so drop it to test and restore it afterwards. This tester lists groups by number rather than by name, so a named group shows up as group 1, 2 and so on.

Lookbehind: JavaScript (since ES2018) and .NET accept variable-length lookbehind such as (?<=\$\s*)\d+. Java accepts it only when the length is bounded, and Python's re and PHP's PCRE have traditionally required a fixed width — rewrite as \$\s*(\d+) and read the capture group instead. Go's RE2 has no lookaround at all.

Unicode: in JavaScript and Java, \d means ASCII 0–9. In Python 3 and .NET it also matches digits from other scripts, such as Arabic-Indic ٣, unless you use re.ASCII or RegexOptions.ECMAScript. Possessive quantifiers (a++) and atomic groups (?>…) exist in Java, PCRE, .NET and Python 3.11+, but not in JavaScript, so patterns using them can't be tested here as written.

How to port a pattern you tested here

Flags are where ports usually break. Here they sit after the closing slash; elsewhere they move. Python: re.compile(p, re.I | re.M | re.S), or inline (?ims) at the start of the pattern. Java: Pattern.compile(p, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL). C#: new Regex(p, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline) — dotall is called Singleline in .NET. PHP: delimiters plus modifiers, as in '/p/ims'.

No other language has a g flag. Global matching is a choice of function instead: re.findall or re.finditer rather than re.search in Python, a while (matcher.find()) loop in Java, Regex.Matches in C#, and preg_match_all rather than preg_match in PHP. Watch Python's re.match too — it only matches at the start of the string, unlike exec here.

Then fix the escaping. The pattern box here takes the regex itself, so \d+ is typed once. In an ordinary Java or C# string literal every backslash doubles, giving "\\d+"; a C# verbatim string @"\d+" or a Python raw string r"\d+" avoids that. In PHP, single quotes keep the backslash: '/\d+/' — and if the pattern contains the delimiter (usually /), escape it or use another delimiter such as #.

Finally, run the same test string through a short script in the target language and compare the match count with what this page reports.

How to use the JavaScript Regex Tester with Capture Groups tool

  1. 1

    Write your pattern

    Type the regular expression between the slashes — no escaping of forward slashes needed.

  2. 2

    Toggle flags

    Enable g (global), i (case-insensitive), m (multiline) or s (dotall) as needed.

  3. 3

    Paste a test string

    Matches highlight in real time, with index positions and capture groups listed below.

  4. 4

    Share it

    Copy a permalink that carries the pattern, flags, and test string to whoever needs to review it.

Frequently asked questions

Which regex flavor does this use?

JavaScript's built-in RegExp engine — the same one in Node.js and every browser. Patterns may behave slightly differently in PCRE (PHP), Python's re, or Go's RE2, especially around lookbehind and Unicode.

Why does my pattern match nothing?

Check that special characters you meant literally (., +, ?, parentheses, brackets) are escaped with a backslash, and that the case-insensitive flag is on if capitalization varies. An error banner appears if the pattern itself is invalid.

Is my test data sent anywhere?

No. Matching runs entirely in your browser — patterns and test strings are never uploaded or logged.

How do I match across multiple lines?

Enable the m flag so ^ and $ anchor at each line, and the s flag if you need the dot to match newline characters too.

Is this a regex generator or builder?

No — it's a tester: you write the pattern and it shows exactly what matches. The reliable way to build one is incrementally: start with a literal sample of what you want, replace one piece at a time with a class or quantifier (\d+ for the number, [a-z-]+ for the slug), and watch the highlights after each change. Paste several should-match and should-not-match lines into the test string so a too-greedy pattern shows up immediately.

Why does my pattern work here but not in Python?

The usual suspects: named groups need (?P<name>…) in Python's re; a variable-length lookbehind that JavaScript allows is rejected; \d matches non-ASCII digits in Python unless you pass re.ASCII; there's no g flag, so you need re.findall or re.finditer; and re.match only matches at the start of the string — use re.search for the behaviour you see here.

Which flags can I use, and can I use \p{L} Unicode escapes?

The tester exposes g, i, m and s. The u, y, d and v flags aren't available, and Unicode property escapes such as \p{L} require u — without it, JavaScript reads \p{L} as the literal text p{L} rather than "any letter", so the pattern silently matches the wrong thing. Test those patterns in Node.js or browser devtools with the u flag set.

Why does a pattern like ^ or \b show only one match even with g?

Patterns that can match an empty string produce zero-length matches. To avoid looping forever on the same position, the tester stops at the first zero-length match. In your own code, advance lastIndex by one after an empty match, or use String.prototype.matchAll, which handles that for you.

Related on TechLogHub

Get the next tool before you need it

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.