Skip to content

Regex Tester

Test regular expressions with live highlighting, match details, and capture group extraction.

//
Enter a pattern to start matching

Regular Expression Basics

A regular expression (regex) defines a search pattern using special characters. . matches any single character. * repeats the preceding element zero or more times. + repeats one or more times. ? makes the preceding element optional. [abc] matches any single character in the set. \d matches digits, \w matches word characters, and \s matches whitespace.

Flags Explained

g (global) finds all matches, not just the first. i makes the pattern case-insensitive. m (multiline) changes ^ and $ to match line boundaries instead of string boundaries. s (dotAll) makes . match newlines. Combine flags as needed: gi finds all matches regardless of case.

Capture Groups

Parentheses create capture groups that extract parts of a match. The pattern (\d{4})-(\d{2})-(\d{2}) matches a date like "2026-03-20" and captures the year, month, and day as separate groups. Named groups use the syntax (?<year>\d{4}) for self-documenting patterns.

Common Patterns

Email (simplified): [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. URL: https?://[^\s]+. IP address: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}. Phone (US): \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}. These patterns cover typical validation scenarios; production use should account for edge cases specific to your data. For URL validation patterns, pair this tool with the URL Encoder/Decoder to handle percent-encoded characters. When extracting structured data, pipe matches into the JSON Formatter to organize your results.

Performance Considerations

Catastrophic backtracking occurs when a pattern with nested quantifiers encounters input that forces the engine to try exponential combinations. A pattern like (a+)+ against the string "aaaaaaaaaaX" can freeze the browser. Avoid nested quantifiers and use possessive quantifiers or atomic groups when your regex engine supports them. This tool runs in your browser, so a runaway pattern only affects your tab.

Frequently Asked Questions

Which regex flavor does this tool use?
This tool uses JavaScript's built-in RegExp engine, which implements the ECMAScript regex specification. Most patterns work the same way in Python, Java, and other languages, but lookbehind support and Unicode handling differ between engines.
Can regex match across multiple lines?
Add the s flag to make . match newline characters. Without it, . matches everything except newlines. The m flag makes ^ and $ match at line boundaries.