Regex Tester

Test and debug regular expressions in real time. Highlights all matches, shows capture groups, counts matches, and supports find-and-replace mode.

/ /
Advertisement

How to Use

Enter your regular expression in the pattern field and any flags (g, i, m, s) in the flags field. Type your test string in the left panel. Matches are shown in the right panel with their positions and captured groups. Switch to Replace mode to see how a substitution pattern transforms your text.

Common Flags

g (global): find all matches. i (case insensitive): ignore case. m (multiline): ^ and $ match line boundaries. s (dotAll): dot matches newlines.

Advertisement

Frequently Asked Questions

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It is used to match, find, or replace strings in text. Regular expressions are supported in nearly every programming language and are essential for text processing, validation, and parsing.

The 'g' (global) flag finds all matches, not just the first one. The 'i' (case insensitive) flag makes the pattern case-insensitive. The 'm' (multiline) flag makes ^ and $ match the start and end of each line instead of the entire string. The 's' (dotAll) flag makes the dot (.) also match newline characters.

A basic pattern for email matching is: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. This is a simplified version; fully RFC-compliant email validation requires a much more complex expression. For most practical purposes, this pattern catches the vast majority of valid email formats.

Capture groups are portions of a regex enclosed in parentheses. They capture the matched text for later use. Group 1 is the first set of parentheses, Group 2 is the second, etc. Named groups use (?...) syntax. In replace operations, you can reference captured text with $1, $2, or $.

Greedy matching (the default) matches as many characters as possible. For example, .+ in 'acd' would match 'acd'. Lazy matching (.+?) matches as few characters as possible, giving ''. Use ? after quantifiers (*, +, ?) for lazy matching.

Related Calculators

More tools in the Developer Tools category.

Advertisement