🧩 Regex Tester

Test JavaScript regular expressions live against your own text. See matches highlighted instantly, with index positions and capture groups for every match.

🧩 Pattern & Test String
Allowed: g (global), i (ignore case), m (multiline), s (dotAll), u (unicode), y (sticky).
🎯 Match Results
Total Matches
Highlighted Test String
Match Details
#IndexMatched TextCapture Groups
⚠️ Uses JavaScript's native RegExp engine (the same one running in your browser). Behavior may differ slightly from PCRE, Python, or .NET regex flavors. Everything runs locally — nothing is transmitted, logged, or stored.
🔍

Enter a pattern and test string to see matches

Guide

About the Regex Tester

This regex tester lets you try out JavaScript regular expressions against your own text and see the results instantly — no compiling, no copy-pasting into a console, no external service. Type a pattern, set flags, paste in a test string, and every match is highlighted directly in the text, with a detailed table listing each match's position and any capture groups it contains. It's built for the exact regex flavor used by JavaScript engines (the same one powering every web browser and Node.js), which is the flavor most web developers need when validating form input, parsing log lines, or writing a find-and-replace.

How It Works

As you type, the tester constructs a native RegExp object from your pattern and flags, wrapped in a try/catch so an invalid or incomplete pattern shows a clear error message instead of breaking the page. When the flags include g (global), it uses String.prototype.matchAll() to collect every match in the string, including each match's start index and any capture groups; without g, JavaScript's regex engine only returns the first match, matching real runtime behavior. The highlighted view is built by walking through the test string and the match positions together, inserting each matched span into the display — using safe DOM text nodes rather than raw HTML insertion, so special characters in your test string are always shown as literal text and can never be interpreted as markup.

Why It Matters

Regular expressions are notoriously easy to get subtly wrong — an unescaped special character, a missing anchor, or a greedy quantifier that matches far more than intended. Testing a pattern against realistic sample text before dropping it into production code (form validation, log parsing, data extraction) catches these mistakes early, when they're cheap to fix, rather than after they've silently rejected valid input or let bad input through.

Tips for Accurate Results

  • Add the g flag to find every match in the string — without it, JavaScript's engine stops after the first match, which is easy to forget when a pattern "isn't matching" the rest of your text.
  • Use named or numbered capture groups — parentheses (...) — to pull out specific pieces of each match rather than just confirming a match occurred; the match details table shows every capture group's value.
  • Test edge cases deliberately: empty strings, strings with only whitespace, strings with special regex characters like . or * that you intend to match literally (remember to escape them with a backslash).
  • Remember JavaScript regex syntax has quirks versus other languages — for example, named lookbehind and some Unicode property escapes require the u flag to work correctly.
  • If a pattern behaves unexpectedly with the m (multiline) flag, double-check whether you actually want ^/$ to match at every line break, or just at the start/end of the whole string.
About

Regex Flags Reference

🌐

g — Global

Finds all matches in the string instead of stopping after the first. Required for matchAll() and for iterating matches with exec() in a loop.

🔡

i, m, s — Case, Lines, Dot

i ignores letter case. m makes ^/$ match at every line break. s (dotAll) lets . match newline characters too.

🎯

u, y — Unicode & Sticky

u enables full Unicode-aware pattern parsing (needed for some escapes and code point ranges). y (sticky) anchors matching to exactly the current search position.

FAQ

Frequently Asked Questions

Common questions about regex testing

Which regex flavor does this tester use?
This tool uses JavaScript's native RegExp engine — the same one that runs in your browser and in Node.js. Syntax can differ slightly from other flavors like PCRE (used in PHP/Python) or .NET regex, especially around named groups, lookbehind support, and Unicode handling.
What do the regex flags g, i, m, s, u, and y mean?
g (global) finds all matches instead of just the first. i (case-insensitive) ignores letter case. m (multiline) makes ^ and $ match at line breaks. s (dotAll) lets . match newline characters. u (unicode) enables full Unicode pattern handling. y (sticky) matches only starting exactly at the current search position.
Why does my pattern only show one match?
Without the g (global) flag, JavaScript's regex engine only returns the first match by design. Add g to the flags field to find and highlight every match in the test string.
Is my test string sent to a server?
No. Everything — pattern compilation, matching, and highlighting — runs locally in your browser using the native RegExp object. Nothing you type is transmitted, logged, or stored anywhere.
How are matches highlighted safely if my test string contains HTML-like text?
The highlighter builds the display using safe DOM text nodes rather than inserting raw HTML, so characters like < and > in your test string are always rendered as literal text and never interpreted as markup, even inside the highlighted match spans.
What does the "Index" column in the match table mean?
Index is the zero-based character position in your test string where that match begins — useful if you're programmatically locating matches with methods like String.prototype.slice() or substring().
Why do I get an error about duplicate flags?
JavaScript doesn't allow the same regex flag to appear twice, like "gg" or "gig". The tester validates the flags field before compiling the pattern and shows a clear error instead of letting the browser throw an uncaught exception.
What does an undefined capture group mean in the results?
A capture group shows as "(undefined)" when that group is optional — for example followed by a ? — and didn't participate in a particular match. It's not an error; it's JavaScript's normal behavior for an optional group that wasn't used.
Can I test multiline text with this tool?
Yes — paste multiline text into the Test String box. By default ^ and $ only match the very start and end of the whole string, so add the m (multiline) flag if you want them to match at the start and end of each line instead.
Why does my pattern show a syntax error even though it looks correct?
JavaScript regex syntax has quirks that differ from other languages — some named-group or lookbehind syntax needs the u flag, and characters like {, }, (, and ) must be escaped when you want to match them literally. The error message echoes the browser's own RegExp compilation error to help you pinpoint the issue.
Does this tool support named capture groups?
Yes — JavaScript's RegExp supports named groups with (?<name>...) syntax. The match details table currently lists all capture groups by position number rather than by name, but named groups match exactly the same as numbered ones.
What happens if I leave the pattern field empty?
An empty pattern returns zero matches and clears the highlighted view and match table. It isn't treated as an error — an empty pattern is technically valid, it just doesn't match anything meaningful.
Can I use this to build a regex for form validation or data extraction?
Yes — test your pattern against realistic sample inputs, including edge cases like empty strings or unexpected characters, then copy the working pattern and flags directly into your code's RegExp constructor or literal syntax.

Related Calculators

Explore other developer & tech tools