Regex Tester
Test and debug regular expressions in real time.
Click a token to insert it into the pattern.
How It Works
Regular expressions (regex) are patterns used to find, match, and extract text. This tester
uses the browser's built-in JavaScript regex engine — the same one used in String.prototype.match(), replace(), and matchAll().
Flags change how matching works: g finds all matches (without it, only the first is returned); i ignores case; m makes ^ and $ match line boundaries instead of the whole string; s (dotAll) makes . match newlines; u enables full Unicode support.
Capture groups let you extract parts of a match. Use () for
numbered groups and (?<name>) for named groups. Non-capturing groups (?:) group without capturing, which is faster when you don't need the captured value.
Greedy vs. lazy: quantifiers like * and + are greedy by default — they
match as much as possible. Adding ? makes them lazy: .*? matches as
little as possible. Be careful with patterns like (a+)+ on long strings —
catastrophic backtracking can cause the browser to hang.
Related Tools
Frequently Asked Questions
What do the regex flags mean?
g = global (find all matches, not just the first). i = case-insensitive. m = multiline (^ and $ match line boundaries). s = dotAll (. matches newlines). u = Unicode (enables full Unicode support and stricter parsing). d = generate match indices (start/end positions).
What is the difference between .* and .*?
.* is greedy — it matches as many characters as possible. .*? is lazy — it matches as few characters as possible. Example: on "aXbXc", a.*X matches "aXbX" (greedy), while a.*?X matches "aX" (lazy).
How do I match a literal dot or parenthesis?
Escape it with a backslash: \. matches a literal dot, \( matches a literal opening parenthesis. Without escaping, . matches any character and ( starts a capture group.
What is a capture group?
Parentheses () create a capture group that extracts the matched substring. Example: (\d{4})-(\d{2})-(\d{2}) on "2024-01-15" captures group 1 = "2024", group 2 = "01", group 3 = "15". Named groups use (?<name>...) syntax.
What causes catastrophic backtracking?
Patterns with nested quantifiers like (a+)+ on long non-matching strings cause exponential backtracking — the engine tries every possible combination before failing. This can freeze the browser tab. Avoid overlapping quantifiers on the same characters.