Regex Tester

Regular expressions are powerful but notoriously difficult to get right.

A single misplaced character can change a pattern from matching exactly what you need to matching nothing or everything. This regex tester lets you write, test, and debug regular expressions in real time with instant visual feedback showing matches highlighted in your test string.

Developers use regex for input validation, text parsing, search and replace, log analysis, and data extraction. Whether you are validating email addresses, parsing log files, extracting URLs from text, or cleaning up data imports, getting the regex right before deploying it is critical. Testing in production is not an option when a bad pattern can cause application errors, data loss, or security vulnerabilities.

This tool provides a live regex testing environment. Enter your pattern, provide test strings, and see matches highlighted instantly. Capture groups are extracted and displayed separately. Flags like global, case-insensitive, and multiline are toggleable. The tool supports JavaScript regex syntax, the most common flavor used in web development.

Regular Expression Basics

A regular expression (regex) is a pattern that describes a set of strings. The pattern uses a combination of literal characters and special metacharacters to define what text should match.

Literal characters match themselves. The pattern cat matches the literal string "cat" wherever it appears.

Metacharacters have special meanings. The most common include:

  • . matches any single character except newline
  • * matches zero or more of the preceding element
  • + matches one or more of the preceding element
  • ? matches zero or one of the preceding element
  • ^ matches the start of a line
  • $ matches the end of a line
  • [] defines a character class (matches any single character listed)
  • () defines a capture group
  • | acts as an OR operator
  • \ escapes a metacharacter to match it literally

Quantifiers control how many times an element can repeat. {3} matches exactly three times. {2,5} matches two to five times. {3,} matches three or more times.

Character classes define sets of characters. [abc] matches a, b, or c. [a-z] matches any lowercase letter. [0-9] matches any digit. Shorthand classes include \d for digits, \w for word characters (letters, digits, underscore), and \s for whitespace.

Common Regex Patterns

Here are patterns developers use frequently, tested and ready to use.

Email validation (basic). ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ matches standard email formats. Note that fully RFC-compliant email validation via regex is extraordinarily complex. This pattern covers the vast majority of real-world email addresses.

URL matching. https?:\/\/[^\s]+ matches HTTP and HTTPS URLs. For stricter matching, add domain and path validation.

Phone numbers (US). \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} matches formats like (555) 123-4567, 555-123-4567, and 5551234567.

IP address (IPv4). \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b matches the format of IPv4 addresses. For strict validation (values 0-255), a more complex pattern is needed.

Date formats. \d{4}-\d{2}-\d{2} matches ISO 8601 dates like 2024-03-29. \d{1,2}\/\d{1,2}\/\d{2,4} matches US-style dates like 3/29/2024.

HTML tags. <[^>]+> matches opening and closing HTML tags. Note that parsing full HTML with regex is generally discouraged. Use a proper HTML parser for complex document processing.

Regex Flags

Flags modify how the regex engine processes the pattern.

Global (g). Without the global flag, the regex stops after the first match. With it, the engine finds all matches in the string. This flag is essential when you want to find or replace every occurrence.

Case-insensitive (i). Makes the pattern match regardless of letter case. hello with the i flag matches "Hello," "HELLO," and "hElLo."

Multiline (m). Changes the behavior of ^ and $. Without multiline, ^ matches only the start of the entire string and $ matches only the end. With multiline, they match the start and end of each line within the string. This is critical when processing text that spans multiple lines.

Dotall (s). Makes the . metacharacter match newline characters in addition to all other characters. Without this flag, . matches everything except newlines.

Capture Groups and Backreferences

Parentheses serve two purposes in regex: grouping and capturing.

Capture groups extract specific portions of a match. The pattern (\d{3})-(\d{4}) applied to "555-1234" produces two capture groups: group 1 contains "555" and group 2 contains "1234." This is invaluable for extracting structured data from text, like pulling dates, IDs, or components from formatted strings.

Named capture groups use the syntax (?<name>pattern) to assign names to groups. (?<area>\d{3})-(?<number>\d{4}) captures "555" in a group named "area" and "1234" in a group named "number." Named groups make code more readable and maintainable.

Non-capturing groups use (?:pattern) when you need grouping for logic but do not need to capture the matched text. This is a performance optimization and reduces confusion in the capture group numbering.

Backreferences reference previously captured groups within the same pattern. \1 references the first capture group. The pattern (\w+)\s+\1 matches repeated words like "the the" or "is is," which is useful for detecting duplicate words in text.

Regex Performance Pitfalls

Poorly written regex can cause catastrophic performance problems, including patterns that take exponential time to evaluate.

Catastrophic backtracking. Nested quantifiers like (a+)+b can cause the regex engine to try an exponential number of combinations on certain inputs. The string "aaaaaaaaaaaaaaac" causes this pattern to backtrack exponentially because the engine tries every possible way to distribute the "a" characters between the inner and outer quantifiers before concluding there is no match.

Greedy vs lazy quantifiers. By default, quantifiers are greedy: they match as much as possible. This can cause unexpected behavior. The pattern <.+> applied to <b>bold</b> matches the entire string <b>bold</b> rather than just <b> because .+ greedily consumes everything including the first >. Using the lazy quantifier <.+?> matches <b> and </b> individually.

Overly broad patterns. Using . to match "anything" often matches more than intended. Be as specific as possible in your patterns. Instead of .@.*, use [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+ for matching email-like patterns.

Debugging Strategies

Build incrementally. Start with the simplest pattern that matches part of your target and add complexity one element at a time. This tool’s real-time highlighting makes incremental building efficient because you see the effect of each change immediately.

Test edge cases. After your pattern matches the expected input, test it against strings that should not match. If your email pattern matches "not-an-email," it is too permissive. If it rejects "[email protected]," it is too strict.

Use comments. In verbose regex mode (available in some languages), use comments to document complex patterns. Even without verbose mode, document your regex in code comments explaining what it matches and why.

For related developer tools, check our JSON Formatter for formatting regex match results, our URL Encoder/Decoder for handling special characters in URL patterns, and our Hash Generator for validating hash format patterns.

Frequently Asked Questions

What is a regular expression?

A regular expression (regex) is a pattern that describes a set of strings. It uses literal characters and special metacharacters to define text matching rules for validation, search, parsing, and replacement operations.

What regex flavor does this tool use?

This tool uses JavaScript regex syntax, which is the most common flavor in web development. Most patterns that work here will also work in other languages with minor syntax adjustments.

How do I match a literal dot or asterisk?

Precede the metacharacter with a backslash to escape it. Use \. to match a literal period and \* to match a literal asterisk. Without the backslash, these characters have special regex meanings.

What is the difference between greedy and lazy matching?

Greedy quantifiers (, +, ?) match as much text as possible. Lazy quantifiers (?, +?, ??) match as little as possible. Greedy matching of <.+> on HTML matches the entire tag structure. Lazy matching of <.+?> matches individual tags.

How do I make a regex case-insensitive?

Add the i flag to your pattern. In this tool, toggle the case-insensitive flag option. In code, add i after the closing delimiter: /pattern/i in JavaScript.

What is a capture group?

A capture group, defined by parentheses, extracts a specific portion of the match. The pattern (\d+)-(\d+) applied to "123-456" captures "123" in group 1 and "456" in group 2.

Why is my regex slow?

Slow regex is usually caused by catastrophic backtracking from nested quantifiers like (a+)+. Avoid nesting quantifiers where possible. Use specific character classes instead of broad wildcards. Test with long strings that do not match.

Can regex parse HTML?

Regex can match simple HTML patterns like individual tags, but parsing full HTML documents with regex is unreliable because HTML is not a regular language. Use a proper HTML parser for complex document processing.

Data accurate as of: March 2026