Regex Tester
Test regular expressions live with match highlighting, groups, and replace preview.
Written by Anil Gautam · Updated
What do the g, i, m, s, u and y flags change?
With g on, the tester lists every match and Replace with changes all of them. Turn it off and only the first match is shown and replaced. The i flag ignores letter case. With m, ^ and $ match at every line break: ^\d+$ finds nothing in a test string with 12 and 34 on separate lines, and finds both numbers once m is ticked. The s flag lets the dot match a newline.
Unicode mode needs u. Without it, \p{L} matches the literal text p{L}, and the dot splits an emoji or any other character outside the Basic Multilingual Plane into two halves. Sticky mode, y, accepts a match only where the previous one ended, starting at position 0: \d with g and y finds 1 and 2 in 12a3 and stops at the a, while g alone also finds the 3.
How do replacement tokens and capture groups work?
Replace with follows the rules of JavaScript's String.replace. $1, $2 and so on insert numbered groups, $<name> inserts a group written as (?<name>...), $& inserts the whole match, $` and $' insert the text before and after it, and $$ writes a dollar sign. To turn DD-MM-YYYY dates into ISO order, use (\d{2})-(\d{2})-(\d{4}) with $3-$2-$1, and Due 07-10-2026, paid 15-10-2026 becomes Due 2026-10-07, paid 2026-10-15.
The Captured groups panel lists each match with its start index and every group by number, named groups included. A group that took no part in a match shows as undefined: (a)|(b) run on b reports $1 = undefined and $2 = b, and $1 in a replacement then inserts nothing.
Why does a pattern match too much or hang the page?
Quantifiers are greedy. On <b>bold</b> and <i>it</i>, the pattern <.+> returns one match covering the whole line, because .+ runs to the last >. Adding ? makes it lazy, and <.+?> returns the four tags separately. \w and \b treat only ASCII letters, digits and the underscore as word characters, so \w+ finds caf in café. With the u flag, [\p{L}\p{M}]+ keeps café and नमस्ते whole, while \p{L}+ alone splits the Hindi word, because its vowel signs and virama are combining marks.
Type the pattern as it would appear between slashes, with single backslashes. When you move it into a JavaScript string, as in new RegExp("\\d"), each backslash must be doubled. The test reruns on every keystroke inside the page, and nested quantifiers such as (a+)+$ can backtrack exponentially on a long run of a characters followed by something else, with each extra character roughly doubling the work. If the tab stops responding, shorten the test string or simplify the pattern. For literal text without regex syntax, Find and Replace is simpler.