Regex Tester

Test regular expressions live: enter the pattern and flags, see the highlighted matches in the text and the list of captured groups.

/ /
Flags

Text with matches highlighted

What is a regular expression?

A regular expression (regex) is a pattern that describes a set of strings. It's used to search, validate and extract text: finding every email in a document, validating a phone number format, replacing parts of a string, and much more. This tool uses JavaScript's own regex engine (the same one used by String.prototype.match), so results reflect your browser's behavior.

The flags

Capture groups

Parentheses in a regex create capture groups: besides matching, they store the matched part for you to reuse. For example, (\d{4})-(\d{2}) captures the year and month separately. Named groups ((?<year>\d{4})) get a name instead of a number. This tool lists each group captured per match.

Frequently Asked Questions (FAQ)

What happens if I type an invalid regex?

The tool shows a readable error message (the same one from the JavaScript engine) and doesn't crash — the highlighting simply isn't applied until you fix the pattern.

Why doesn't a regex like a* with the g flag freeze the page?

Patterns that can match an empty string (zero-width) could cause an infinite loop. The tool manually advances the position after each empty match, exactly as recommended when iterating RegExp.exec.

Is the highlight safe against malicious code in the text?

Yes. The test text is never inserted as HTML. Each snippet (matched or not) is added to the result as a text node or inside a <mark> via textContent, which eliminates the risk of XSS.