Free Regex Tester — Test Regular Expressions in Real Time

Test and debug regular expressions in real time. Highlights all matches, shows capture groups and match positions, includes a quick-reference cheat sheet, and has common pattern presets for email, phone, URL, IP address, and date formats.

Common patterns

//

More Developer & Design tools

See all →

What is this calculator for?

You're debugging a form validation regex that's rejecting valid emails. Or you need to extract all phone numbers from a 2,000-line log file. Or you're learning regex from scratch and need an interactive playground to test patterns. The regex tester lets you build, test, and debug regular expression patterns against sample text in real time — seeing matches highlighted, capture groups identified, and error messages explained.

Regular expressions (regex) are a pattern-matching language for text. Used in: form validation (email, phone, URL formats), search and replace operations, log parsing, data extraction, syntax highlighting, configuration files. Every modern programming language supports regex with slight syntax variations. The basics: literal characters (a, b, 1, 2) match themselves; metacharacters (., +, *, ?, [], (), {}) have special meaning. Combining these into patterns lets you describe text categories precisely.

This tool tests patterns against input text, highlighting matches and showing capture groups. Supports common regex flavors (PCRE / JavaScript / Python style). Use to verify your pattern before deploying to production code.

How to use this calculator

Enter your regex pattern (e.g., \d{3}-\d{3}-\d{4} for phone numbers) and the test text you want to match against. The tool highlights matches in real time as you adjust the pattern.

Use flags to modify behavior: i (case-insensitive), g (global, find all matches not just first), m (multiline), s (dotall — . matches newlines too).

For capture groups: parenthesize portions of the pattern you want to extract. (\d{3})-(\d{3})-(\d{4}) matches phone numbers AND captures the three parts separately. Useful when extracting structured data from text.

For common patterns: email ^[\w.+-]+@[\w-]+\.[\w.-]+$. US phone \(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}. URL https?://[\w.-]+(?:/[\w./?%&=-]*)?. Date YYYY-MM-DD \d{4}-\d{2}-\d{2}. SSN \d{3}-\d{2}-\d{4}. Hex color #[0-9a-fA-F]{6}.

Understanding your results

The tester returns matched substrings, capture groups for each match, and execution time information.

Regex syntax essentials. Metacharacters: . (any character except newline), \d (digit), \D (non-digit), \w (word char: letter, digit, underscore), \W (non-word), \s (whitespace), \S (non-whitespace). Quantifiers: * (0+), + (1+), ? (0 or 1), {n} (exactly n), {n,m} (n to m). Anchors: ^ (start of line/string), $ (end), \b (word boundary). Character classes: [abc] (a, b, or c), [^abc] (NOT a, b, c), [a-z] (range). Groups: () (capture), (?:) (non-capture), (?=) (lookahead), (?<=) (lookbehind).

Common regex pitfalls. Greedy vs lazy quantifiers: .+ is greedy (matches as much as possible); .+? is lazy (matches as little as possible). For matching content between tags: lazy is usually what you want. Escape special characters: . in regex means "any character"; to match a literal dot, escape as \.. Same for parentheses, brackets, plus, etc. Anchors matter: ^abc$ matches only strings that ARE exactly "abc"; without anchors, matches "abc" anywhere in the string.

Email validation reality. The "perfect" email regex is hundreds of characters long because the email spec (RFC 5322) is complex. For practical use: a simple pattern like ^[\w.+-]+@[\w-]+\.[\w.-]+$ covers 99% of real emails and rejects most invalid ones. Trying to perfectly validate emails with regex is a rabbit hole; better practice is rejecting obviously-malformed, then sending a confirmation email (deliverability = truth).

Performance considerations. Catastrophic backtracking: poorly-written regex patterns can have exponential runtime on certain inputs. (a+)+ against a long string of "a" characters can take exponentially long. For production code: test regex performance with large inputs; consider compiled regex if used repeatedly; use non-capturing groups when capture isn't needed.

A worked example

Marcus needs to extract all dates from a log file. Format example: "2025-03-14T08:42:15Z user login successful." He wants to extract just the date portion (YYYY-MM-DD).

Pattern attempt 1: \d{4}-\d{2}-\d{2}. Tests in regex tester against sample log lines. Matches "2025-03-14" correctly. But also matches "1234-56-78" (clearly not a real date) — too loose. Acceptable for his use case since log file only contains real dates.

For tighter validation: (?:19|20)\d{2}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]). This validates year starts with 19 or 20, month is 01-12, day is 01-31. Rejects "1234-56-78." Trade-off: longer, harder to read, more potential for bugs. For most use cases, the simpler pattern is fine.

Extension: he wants to capture year, month, day separately. Pattern: (\d{4})-(\d{2})-(\d{2}). Now each match returns 3 capture groups for analysis (count occurrences per month, per year, etc.).

Variation: Lin is validating phone numbers in a registration form. She wants to accept multiple formats: "555-123-4567", "(555) 123-4567", "555.123.4567", "5551234567". Pattern: ^\(?(\d{3})\)?[-. ]?(\d{3})[-. ]?(\d{4})$. Tests against each format — all match correctly. Also captures area code, prefix, and line number separately for processing. The pattern doesn't validate that the number is real (no way to do that with regex alone), just that the format is plausible.

Caveat: she also needs to reject obviously fake numbers (555-555-5555, 000-000-0000). She adds an explicit reject pattern in code, post-regex-match. Regex handles format validation; business logic handles content validation. Trying to encode "not all 5s" in regex is possible but ugly; cleaner to do it in code.

Related resources

For general text manipulation, see Word Counter and Case Converter. For URL encoding (often paired with regex for URL extraction), the URL Encoder. Regex101 is the most popular interactive regex tester with detailed pattern explanations; RegExr is another popular interactive tool; Regular-Expressions.info is the comprehensive reference for regex syntax and theory.

Frequently Asked Questions

What is a regular expression (regex)?

A regular expression is a sequence of characters that defines a search pattern. You can use regex to find, validate, extract, or replace text — for example, validating that an email address has the right format, or extracting all phone numbers from a document.

How do I learn regex?

Start with the basics: literal characters match themselves, `.` matches any character, `\d` matches a digit, `*` means zero or more. Practice with a tool like this tester, then try regexr.com or regular-expressions.info for deeper tutorials.

What are the most common regex patterns?

Email: /^[\w.-]+@[\w.-]+\.\w{2,}$/ · Phone (US): /\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}/ · URL: /https?:\/\/[\w.-]+(?:\/[\w.-]*)*/ · Date (YYYY-MM-DD): /\d{4}-\d{2}-\d{2}/ · ZIP code: /\d{5}(-\d{4})?/

What are capture groups in regex?

Capture groups, written with parentheses `(pattern)`, let you extract specific parts of a match. For example, `/([\w.-]+)@([\w.-]+)/` applied to 'user@example.com' gives group 1 = 'user' and group 2 = 'example.com'. Non-capturing groups use `(?:pattern)` — they group without capturing.

When should I use regex vs string methods?

Use string methods (`includes`, `startsWith`, `split`, `replace`) for simple operations — they're faster and more readable. Switch to regex when you need pattern matching (find any email), multiple replacements with the `g` flag, or validation (ensure a string has exactly the right format).

Why does regex have so many syntax variations?

Different tools and languages implemented regex independently in the 1970s-90s with their own conventions. POSIX BRE (basic), POSIX ERE (extended), PCRE (Perl-Compatible), JavaScript, Python's re, .NET regex, Java regex — each slightly different. Most modern languages and tools (JavaScript, Python, Java, .NET, Go, PHP, Ruby) use PCRE-compatible or similar syntax. Older tools (grep, sed, vim) use POSIX BRE. The differences are usually minor (escape character handling, named groups syntax, some less-common features). For most everyday use, the basic syntax works across all flavors; advanced features may require flavor-specific code.

Can I use regex to validate email addresses?

Yes, but imperfectly. The full email format spec (RFC 5322) is complex; a 'perfect' validation regex is enormous. Practical patterns like <code>^[\w.+-]+@[\w-]+\.[\w.-]+$</code> handle 99% of valid emails and reject most invalid. The truly correct approach: simple regex to reject obvious garbage, then send a confirmation email — the only way to know an email is valid is whether it can receive mail. Never rely on regex alone for high-stakes email validation.

What's the difference between greedy and lazy regex?

Greedy: quantifiers (*, +) match as much as possible. <code>.*</code> against "a [first] and b [second]" matches the entire string. Lazy: quantifiers (*?, +?) match as little as possible. <code>.*?</code> against same string matches only what's needed. Example: extracting text between brackets. Greedy: <code>\[.*\]</code> matches "[first] and b [second]" (everything from first [ to last ]). Lazy: <code>\[.*?\]</code> matches "[first]" then "[second]" separately. For matching content between delimiters: lazy is almost always what you want.

Are regular expressions case-sensitive?

By default, yes. The <code>i</code> flag enables case-insensitive matching. <code>/Hello/</code> matches "Hello" but not "hello" or "HELLO". <code>/Hello/i</code> matches all three. Most languages and tools support the i flag. Some use different syntax: Python uses <code>re.IGNORECASE</code>, .NET uses <code>RegexOptions.IgnoreCase</code>, but the underlying behavior is the same. For matching usernames, hashtags, file extensions — anywhere case shouldn't matter — always use the case-insensitive flag.

What is catastrophic backtracking?

A regex performance failure where certain patterns take exponential time on certain inputs. Classic example: <code>(a+)+b</code> against "aaaaaaaaaaaaaaaaaaaaa" (no trailing b). The regex engine tries an enormous number of combinations before giving up. Such patterns can crash applications by consuming all CPU. Common causes: nested quantifiers (<code>(x+)+</code>, <code>(x*)*</code>), alternative branches that overlap (<code>(a|aa)*</code>). For production use: test regex patterns against large inputs; consider RE2-compatible patterns (Go's regex doesn't support backreferences but is guaranteed linear time); fail fast with timeouts on user-input regex. RegexBuddy, RegEx101, and the Mubboo regex tester help identify performance problems before deployment.

Sources