Regex Tester
Test and debug regular expressions in real-time with match highlighting, capture groups, and flag support.
How to Use This Regex Tester
Enter a regular expression pattern in the top input field, set your desired flags using the checkboxes or the flags input, and type or paste your test string in the textarea. Matches are highlighted in real-time as you type, and detailed match information including capture groups is displayed below.
What Are Regular Expressions?
Regular expressions (regex or regexp) are sequences of characters that define search patterns. They are used in virtually every programming language for string matching, validation, search-and-replace operations, and text parsing. A regex pattern can match simple literal text or complex patterns involving repetition, alternation, and grouping.
Regular expressions were first formalized by mathematician Stephen Kleene in the 1950s as part of formal language theory. Today they are an essential tool for developers, data scientists, system administrators, and anyone who works with text data. Common uses include email validation, URL parsing, log file analysis, and data extraction.
The power of regex comes from its special metacharacters: . matches any character, * means zero or more repetitions, + means one or more, ? means optional, \d matches digits, \w matches word characters, and \s matches whitespace. Character classes like [a-z] match ranges, and groups () capture subpatterns for extraction.
Flags modify how the regex engine interprets the pattern. The global (g) flag finds all matches instead of stopping at the first. Case-insensitive (i) ignores letter case. Multiline (m) makes ^ and $ match line boundaries. DotAll (s) makes . match newline characters too.
Common Regex Patterns
Examples
Extract numbers: Pattern \d+ with flag g on the text "Order 42 has 3 items at $15 each" will match "42", "3", and "15".
Validate email: Pattern ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$ will match "user@example.com" but not "invalid@" or "@domain.com".
Capture groups: Pattern (\w+)@(\w+\.\w+) on "user@site.com" captures Group 1: "user" and Group 2: "site.com".
Frequently Asked Questions
What is the difference between * and + in regex?
* matches zero or more occurrences of the preceding element, while + matches one or more. For example, a* matches an empty string but a+ requires at least one "a".
How do I match a literal dot or special character?
Escape it with a backslash: \. matches a literal dot, \$ matches a dollar sign, \\ matches a backslash. Inside a character class [], most special characters lose their meaning.
What are non-capturing groups?
Non-capturing groups (?:...) group patterns together without creating a capture group in the results. Use them when you need grouping for alternation or quantifiers but don't need to extract the matched text.