Regex Tester

Test and debug regular expressions with live match highlighting.

instant live highlighting offline
g
Input
Preview 0 matches
Start typing a pattern above…
Result
Match count
matches
First match at
index
Capture groups
Replaced preview
Enable replacement above to see result.

Regex Tester lets you write and debug regular expressions instantly — paste a pattern and test string to see every match highlighted in color, with capture groups and positions shown.


Regular Expression Basics

What are regular expressions?

Regular expressions (regex) are patterns used to search, match, and extract text. They are built into almost every programming language and text editor. Common tokens: \d matches any digit, \w matches a word character, . matches any character, and * or + control repetition. Anchors like ^ and $ match the start and end of a line.

Understanding flags

Flags modify how a pattern is applied. The g flag finds all matches instead of stopping after the first. The i flag makes matching case-insensitive so 'Hello' and 'hello' both match [Hh]ello. The m flag makes ^ and $ match the start and end of each line rather than the whole string. Flags can be combined freely.

Common use cases

Regex is widely used for form validation (emails, phone numbers, zip codes), find-and-replace in code editors, log file parsing, data extraction from HTML or CSV, and URL routing in web frameworks. The preset patterns in this tool cover the most common everyday cases so you can get started without memorizing syntax.

Formula
new RegExp(pattern, flags).exec(string)

Frequently Asked Questions

Why does my pattern match nothing even though it looks right?

The most common cause is a missing g flag — without it, only the first match is found and the tool may still show count 1. Also check that backslashes are entered as single backslashes (\d, not \\d) in the pattern field; the tool handles escaping internally.

What is a capture group and how do I create one?

Wrap part of your pattern in parentheses to create a capture group, e.g. (\w+)@(\w+). Each group captures the text that matched that portion separately. The Capture groups card shows the values from your first match, numbered in the order they appear left to right.

How do I match a literal dot, parenthesis, or other special character?

Escape it with a backslash: \. matches a literal dot, \( matches a literal open parenthesis. Without the backslash, . means 'any character' and ( starts a capture group.

What is the difference between .* and .+?

.* matches zero or more of any character, so it can match an empty string. .+ requires at least one character. Use .+ when you know something must be present, and .* when the section might be empty.

Can I use this tool to test regex for Python, Java, or other languages?

This tool uses JavaScript's RegExp engine, which is very similar to regex in most languages. Syntax for basic patterns, quantifiers, and groups is identical. Some advanced features like lookbehind (supported in modern JS) or named groups may differ slightly between languages.

What is the formula for the Regex Tester?

The tool runs: new RegExp(pattern, flags).exec(string). For global matching it uses the g flag variant in a loop — globalRe.exec(testString) — collecting every match, its index, length, and capture group values until no matches remain.