Tech
Regex Tester
Test JavaScript regular expressions against any text. Run test, match-all, replace, or split with full flag support (gimsuy), capture and named groups, and live results. Runs entirely in your browser.
Test, match, replace, and split with a regex
2 matches
- 4word
- 27word
- Flags used
- g
- Pattern complexity
- simple
Frequently Asked Questions about the Regex Tester
Which regex flavor does this tester use?
It uses the JavaScript regex engine that ships with your browser, which follows ECMAScript 2018+ semantics. That is close to Perl and PCRE for the basics (character classes, quantifiers, anchors, alternation, capture groups), but differs in a few places: there are no possessive quantifiers (a++), no atomic groups ((?>...)), no recursion ((?R) or (?1)), no inline flag modifiers ((?i)...), and lookbehind shipped only in 2018 so older engines may reject (?<=...). Named groups use (?<name>...), not Python's (?P<name>...). If your pattern works in Notepad++, grep, or a PHP preg_* function but not here, those quirks are usually the reason.
What do the g, i, m, s, u, and y flags do?
g (global) keeps the engine going after the first match, which match-all, replace-all, and split need. i (insensitive) ignores letter case, so /abc/i matches ABC and AbC. m (multiline) makes ^ and $ match at every line break, not only at the start and end of the whole string. s (dotall) lets the . metacharacter match a newline too. u (unicode) turns on full Unicode support so \u{1F600} and Unicode property escapes like \p{Letter} work. y (sticky) anchors the next match to the engine's lastIndex, useful for parsing tokens in sequence. The tester accepts any combination of those six and rejects any other character.
What is the difference between capture groups and named groups?
A capture group is anything inside plain parentheses, like (\d{4}). It is numbered left to right starting at 1, and you reference it by position: $1 in a replacement, m[1] on a match object. A named group adds a label with (?<name>...), so (?<year>\d{4}) gives you m.groups.year on the match and $<year> in the replacement. Named groups still keep their numeric index, so a year group at position 1 is reachable as either $1 or $<year>. Use names when a pattern has more than two or three groups, or when the meaning of a group is not obvious from its position.
What is catastrophic backtracking and how do I avoid it?
Catastrophic backtracking happens when a pattern allows the engine to retry the same substring exponentially many ways before giving up. The classic shape is nested quantifiers on overlapping content: (a+)+, (.*)*, or (a|aa)+ run against "aaaaaaaaaaaaaa!" can lock a browser tab for seconds or minutes. JavaScript's engine has no way to abort a running regex from the outside, which is why this tester caps the test string at 100,000 characters and the pattern at 1,000 characters as a defensive bound. To avoid the trap, make every alternative inside a quantified group consume a clearly different prefix, prefer a tighter character class like [^>]* over .*, and add anchors (^ or $) wherever you know where the match has to start or end.
When should I use replace versus match-all?
Use replace when you want a transformed copy of the input, like turning every email address into a hyperlink or stripping every HTML tag. Replace returns one string and a count of how many substitutions happened, and the replacement string can reference capture groups with $1, $<name>, and the special tokens $&, $`, $', and $$. Use match-all when you only need to extract data: every match, its index, and its groups arrive as a list you can iterate. Match-all needs the g flag (the tester adds it for you), and unlike replace it does not modify the input at all, which makes it the right tool for scanning, validation, and pulling structured fields out of free text.