Test and debug regular expressions with real-time match highlighting, group captures, and replace mode
//g
Flags:
Mode:
Common Patterns
Matches
Regex Pitfalls Worth Knowing
Core concepts
Greedy matching: `.*` matches as much as possible β `<.*>` swallows all of `<a><b>`. Use `.*?` for lazy matching.
Anchors: without `^` and `$`, partial matches pass. Full-string validation needs `^...$`.
Escaping: to match `.`, `+`, `?`, `(`, `[` literally, escape them (`\.`).
The performance trap (ReDoS)
Nested quantifiers like `(a+)+` can go exponential on crafted input and take down a service (ReDoS). If a regex runs on user input server-side, keep the pattern simple.
Practical advice
There is no truly 'perfect' email or URL regex. Validate format loosely, then confirm by doing the real thing β sending the email, fetching the link. That design survives edge cases regex never will.
Frequently Asked Questions
A regex tester is an online tool that lets you write and test regular expressions against sample text in real time. It highlights matches, shows captured groups, and helps you debug patterns before using them in code. This saves development time and reduces errors.
Flags modify how the regex engine processes the pattern. The 'g' (global) flag finds all matches instead of stopping at the first one. The 'i' flag makes the pattern case-insensitive. The 'm' (multiline) flag makes ^ and $ match line boundaries. Toggle them using the flag buttons above the pattern input.
Capturing groups are created by wrapping part of a pattern in parentheses, like (\d+). They capture the matched text so you can reference it later using $1, $2, etc. in replacements, or access it programmatically. Named groups use the syntax (?<name>pattern).
Replace mode lets you specify a replacement string that replaces matched text. You can use backreferences like $1, $2 to insert captured groups, $& for the full match, $` for text before the match, and $' for text after. Switch to Replace mode using the toggle above.
Catastrophic backtracking occurs when a regex pattern has nested quantifiers or ambiguous alternations that cause the engine to try exponentially many paths. For example, (a+)+ against a long string of 'a's followed by a non-matching character. This tool limits execution time to prevent browser freezing.
A common email regex is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. This matches most standard email formats. Use the 'Email' preset button to load it automatically. Note that fully RFC-compliant email validation is extremely complex.
.* is a greedy quantifier that matches as many characters as possible, while .*? is lazy (non-greedy) and matches as few characters as possible. For example, in '<b>bold</b>', '<.*>' matches the entire string, but '<.*?>' matches only '<b>'.
Yes, modern JavaScript supports all four lookaround assertions: positive lookahead (?=...), negative lookahead (?!...), positive lookbehind (?<=...), and negative lookbehind (?<!...). They match a position without consuming characters. Lookbehind is supported in ES2018+.
Use a pattern like https?://[\w\-._~:/?#[\]@!$&'()*+,;=%]+ to match HTTP and HTTPS URLs. Click the 'URL' preset to load this pattern. For stricter validation, you may need a more specific pattern depending on your requirements.
Yes, this tool uses the JavaScript RegExp engine directly in your browser. All patterns are tested with native JavaScript regex, so results will match exactly what you'd get in Node.js or browser JavaScript code.