Regex Tester

Text & Data Tools
Regex Tester
/ /
Results
Match Info
Highlighted Matches
Capture Groups
Match # Full Match Groups Index
Copy this code to embed: <iframe src="../../calculators/text-data/regex-tester?embed=1.html" width="100%" height="500" frameborder="0" style="border:1px solid #e2e8f0;border-radius:8px;"></iframe>
Advertisement
How to Use This Calculator

How to Use the Regex Tester

The Regex Tester lets you write, test, and debug regular expressions against sample text in real time. Matches are highlighted instantly as you type the pattern, making it an indispensable tool for developers working with text processing, input validation, and data extraction.

Getting Started

Enter your regular expression in the pattern field and paste your test text in the input area. Matches are highlighted in the text as you type. The results panel shows each match with its position, captured groups, and the matched text. Flags (g, i, m, s) can be toggled with checkboxes.

Common Regex Patterns

Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} matches standard email formats.

Phone: \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} matches US phone numbers in various formats.

URL: https?://[\w\-]+(\.[\w\-]+)+[/\w\-.,@?^=%&:/~+#]* matches HTTP/HTTPS URLs.

IP Address: \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b matches IPv4 addresses.

Date (YYYY-MM-DD): \d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) matches ISO 8601 date strings with basic validation of month and day ranges.

Regex Flags Explained

g (global): Find all matches, not just the first. i (case-insensitive): Match regardless of letter case. m (multiline): ^ and $ match start/end of each line, not just the string. s (dotAll): Makes . match newline characters too.

Regex Flavors

Different programming languages implement slightly different regex engines. This tester uses JavaScript (ECMAScript) regex, which is widely compatible but has some differences from other flavors. PCRE (used in PHP, Perl) supports recursive patterns, possessive quantifiers, and atomic groups that JavaScript lacks. Python's re module is similar to JavaScript but uses named groups with (?P<name>...) syntax instead of (?<name>...). .NET regex supports balancing groups for matching nested structures. When porting patterns between languages, always test them in the target environment, as subtle differences in behavior can cause unexpected failures.

Capture Groups

Parentheses create capture groups that extract specific parts of a match. In the pattern (\d{4})-(\d{2})-(\d{2}) applied to "2025-01-15", group 1 captures "2025", group 2 captures "01", and group 3 captures "15". Named groups use the syntax (?<year>\d{4}). Non-capturing groups (?:...) group tokens without creating a capture, which is useful when you need grouping for alternation or quantifiers but do not need to extract the matched text.

Lookahead and Lookbehind

Lookahead and lookbehind are zero-width assertions that match a position based on what comes before or after, without consuming characters. A positive lookahead (?=...) matches a position followed by the specified pattern — for example, \d+(?= dollars) matches digits only when followed by " dollars." A negative lookahead (?!...) matches a position not followed by the pattern. Lookbehind works similarly but checks what precedes the current position: (?<=\$)\d+ matches digits preceded by a dollar sign. Lookbehinds in JavaScript require modern browsers (Chrome 62+, Firefox 78+, Safari 16.4+).

Performance Pitfalls

Poorly written regex patterns can cause catastrophic backtracking, where the engine takes exponentially longer as input size grows. This commonly happens with nested quantifiers like (a+)+ or overlapping alternatives like (a|a)+. Avoid patterns where multiple parts of the regex can match the same characters. If a pattern runs slowly, simplify the alternation, use atomic groups (where supported), or add anchors to constrain the search space. Always test your regex with both matching and non-matching inputs of varying length to catch performance issues early.

Frequently Asked Questions

Q: Why does my regex match too much (greedy matching)?

A: Quantifiers like * and + are greedy by default, matching as much as possible. Add a ? after them for lazy (non-greedy) matching. For example, <.*> matches an entire tag pair, while <.*?> matches just the first tag. Lazy matching stops at the earliest valid endpoint.

Q: Which regex flavor does this tester use?

A: This tester uses JavaScript (ECMAScript) regular expressions. Syntax is compatible with most languages but some features differ. Lookbehinds require modern browsers. PCRE features like recursive patterns and conditional groups are not available in JavaScript regex.

Q: How do I match special regex characters literally?

A: Escape special characters with a backslash. To match a literal period, use \. instead of . (which matches any character). Characters requiring escaping include: . * + ? ^ $ { } [ ] ( ) | \. Inside character classes [ ], most special characters are literal.

Q: What is the difference between .* and .*? in regex?

A: The pattern .* is greedy and matches as many characters as possible, while .*? is lazy and matches as few characters as possible. In the string "abc def ghi", the pattern ".*" (with quotes) greedily matches the entire string including both quotes, while ".*?" matches only "abc def ghi" — stopping at the first closing quote.

Advertisement
Advertisement