Regex Tester

Test regular expressions with live matching, highlighting, and substitution.

//

About the Regex Tester

The Regex Tester lets you test regular expression patterns against any input string with live match highlighting and capture group display. Type a pattern and a test string, choose your flags, and see every match highlighted in real time. Supports substitution mode to preview how String.replace() transforms your input.

Regular expressions (regex) are sequences of characters that define a search pattern. They are used in virtually every programming language for tasks like input validation, log parsing, data extraction, URL routing, and find-and-replace operations. Writing a regex is straightforward; verifying that it matches exactly what you intend — and nothing it shouldn't — is where a live tester is essential.

Supported flags: g (global — find all matches), i (case-insensitive), and m (multiline — ^ and $ match line boundaries). All regex processing runs locally in your browser using JavaScript's built-in RegExp engine.

Frequently Asked Questions

What are regular expressions?

Regular expressions (regex) are sequences of characters that define a search pattern. A regex engine scans text for substrings matching the pattern. They are used in every programming language for validation, parsing, extraction, and transformation of text data.

What regex flags does this tool support?

g (global — find all matches, not just the first), i (case-insensitive — A matches a), and m (multiline — ^ matches the start of each line, not just the start of the string).

How do I use capture groups?

Wrap a part of your pattern in parentheses: (\d{4})-(\d{2})-(\d{2}) captures year, month, and day separately. Captured groups appear in the match results and can be referenced in replacement strings as $1, $2, etc.

What's the difference between .* and .*??

.* is greedy — it matches as many characters as possible. .*? is lazy — it matches as few characters as possible. For example: <.*> would match the entire string <b>bold</b>, while <.*?> would match <b> and </b> separately.

Why does my regex match here but not in my code?

The most common cause is forgetting to escape backslashes in string literals. In JavaScript, new RegExp("\\d+") is equivalent to the literal /\d+/. Also verify that you are using the same flags in both places.