Regex Tester
Write a regular expression, paste test text and see matches highlighted live — with capture groups, flags and clear error messages.
1,029 views
0 matches
How It Works
A regular expression describes a pattern of characters instead of a literal string, letting one short expression match an entire family of text: any email address, any phone number in several formats, any line in a log file that starts with "ERROR". Type a JavaScript regular expression, toggle its flags (g all matches, i case-insensitive, m multiline anchors, s dot matches newline, u full Unicode) and paste sample text: every match is highlighted in place and listed below with its position and any capture groups. Parentheses () create a capture group — a way to pull out a specific piece of the matched text, such as the domain from an email address or the year from a date, rather than just knowing that a match occurred.
One distinction trips up almost everyone at first: greedy versus lazy quantifiers. .* is greedy — it tries to match as much text as possible, then backtracks only if needed. Against the input <b>bold</b> and <i>italic</i>, the pattern <.*> greedily matches all the way from the first < to the very last >, swallowing both tags. Adding a ? to get .*? makes it lazy — it matches as little as possible, so <.*?> stops at the first > and correctly matches just <b>. This distinction is exactly why naive HTML-matching regexes break on real-world markup.
What You Should Know
The engine here is your browser own native JavaScript (ECMAScript) regex implementation, so a pattern that matches here matches identically in your JS code — there is no translation layer to second-guess. Other languages' regex flavors — PCRE (PHP), Python's re, Java's Pattern — share most of the core syntax (character classes, quantifiers, groups) but diverge on advanced features: lookbehind support, named-group syntax, possessive quantifiers, and some escape sequences differ. Always re-test edge cases in the actual target language before shipping.
Watch for catastrophic backtracking: patterns with nested or overlapping quantifiers, like (a+)+b tested against a long string of "a" characters with no trailing "b", can force the engine into exponential backtracking and freeze the page — or your production server, for the same reason. If a pattern hangs here, shorten the test input first, then restructure the pattern (often by removing the nested repetition entirely) rather than just throwing more CPU at it. Everything runs locally in your browser; no pattern or text is ever transmitted.
Frequently Asked Questions
Which regex flavour does this use?
JavaScript (ECMAScript) — the browser's native engine. Patterns behave exactly as they would in your JS code; PCRE and Python share most syntax but differ in some advanced constructs.
What do the flags mean?
g finds all matches instead of the first; i ignores case; m makes ^ and $ match per line; s lets the dot match newlines; u enables full Unicode handling.
Why does my pattern freeze the page?
Certain patterns with nested quantifiers (like (a+)+b) can backtrack catastrophically on long inputs. Shorten the test text or restructure the pattern — the same freeze would hit your production code.
What is a capture group and why does it matter?
Parentheses around part of a pattern create a capture group, which extracts that specific substring separately from the full match — for example (\d{4})-(\d{2})-(\d{2}) matched against a date gives the year, month and day as three individual captures instead of just confirming the whole string looked like a date. Non-capturing groups, written (?:...), group for structure without producing an extra capture.
Why did my pattern match more (or less) text than expected?
Almost always a greedy-vs-lazy mismatch. .* and similar quantifiers grab as much as possible by default; add a ? (.*?, +?) to make them lazy and stop at the first possible point instead of the last. This single character is usually the fix when a regex over-matches across multiple lines or tags.
Similar Tools
Report a Problem
Regex Tester
Comments
No comments yet — be the first to write one!