Regex Tester: Test & Debug Regular Expressions Online

Type a pattern, paste a test string, see matches highlighted instantly. Capture groups, flags, error messages: all live as you type. Uses JavaScript regex engine (same as your browser and Node.js). Nothing leaves your browser.

Regular Expression Pattern
Enter regex pattern
//

Flags

Test String
Enter string to test
Test and debug your regular expressions

Character Classes

  • . Any character
  • \d Digit (0-9)
  • \w Word character
  • \s Whitespace

Quantifiers

  • * 0 or more
  • + 1 or more
  • ? 0 or 1
  • {n,m} n to m times

Anchors

  • ^ Start of line
  • $ End of line
  • \b Word boundary
  • \B Non-word boundary
Learn More

Regular Expressions in 90 Seconds

A regex is a mini-language for describing text patterns. The pattern \d{3}-\d{4} matches phone numbers like "555-1234". The pattern ^From:.+$ matches email header lines starting with "From:". Simple concept, but the syntax gets dense fast.

JavaScript uses the ECMAScript regex flavor (defined in ECMA-262). Key differences from other flavors: no lookbehind in older engines (added in ES2018), no possessive quantifiers, no atomic groups. If you're porting a regex from Python or PCRE, watch out for these gaps.

The most common mistake I see: forgetting that . doesn't match newlines by default. If your test string has line breaks and your pattern uses .*, you'll get unexpected partial matches. Add the s flag (dotAll) or use [\s\S]* instead.

Performance trap: nested quantifiers like (a+)+ or (.*a){20} can cause catastrophic backtracking. The engine tries exponentially many paths. A 30-character input can hang your browser for minutes. This tool runs in your browser, so a bad pattern only freezes this tab, not a production server. Test here first.

How to Use

  1. 1Enter your regex pattern. No delimiters needed (just the pattern, not /pattern/).
  2. 2Set flags: g (all matches), i (case-insensitive), m (multiline), s (dot matches newline).
  3. 3Paste your test string. Matches highlight in real time.
  4. 4Check capture groups below. Each () group shows its matched content separately.

When You'll Use This

Validating user input formats

Email, phone number, postal code, credit card: all have patterns. Build and test the regex here before dropping it into your validation code. Tip: don't use regex for email validation in production (use a library), but regex is fine for "does this look roughly like an email" client-side checks.

Extracting data from log files

Server logs, CSV files, API responses: when you need to pull timestamps, IPs, or error codes from unstructured text. Build a pattern with capture groups, test it against a sample log line, then use it in your script.

Find-and-replace in code editors

VS Code, IntelliJ, Sublime: all support regex find-and-replace. Build your pattern here with test cases, then paste it into your editor. Especially useful for refactoring: renaming variables, changing function signatures, updating import paths.

Debugging a regex that "should work but doesn't"

You wrote a pattern, it works for some inputs but fails for others. Paste the failing input here, see exactly where the match breaks. Usually it's a missing escape (\. vs .), a greedy vs lazy quantifier (.* vs .*?), or a missing flag.

Common Pitfalls

1

Escape your special characters

In regex, . * + ? ^ $ { } [ ] ( ) | \ all have special meaning. To match a literal dot, use \. not just a dot. I've seen production bugs where someone used "192.168.1.1" as a regex pattern, matching "192x168y1z1" because unescaped dots match any character.

2

Greedy vs lazy: .* vs .*?

.* grabs as much as possible (greedy), .*? grabs as little as possible (lazy). Pattern: <tag>(.*)</tag> on input "<tag>a</tag><tag>b</tag>". Greedy matches "a</tag><tag>b", lazy matches just "a". When in doubt, use lazy with .*? and add specificity.

3

Anchors matter: ^ and $ with multiline flag

Without the m flag, ^ matches only the start of the entire string and $ only the end. With m flag, they match start/end of each line. If you're processing multi-line text and your pattern uses ^, you probably want the m flag.

4

Avoid catastrophic backtracking

Patterns like (a+)+ or (x+x+)+y can take exponential time on non-matching inputs. The regex engine tries every possible way to split the input between the nested quantifiers. Rule of thumb: never nest quantifiers on overlapping character classes. Use atomic groups or possessive quantifiers in flavors that support them.

Examples

Extract date components

Capture year, month, day from ISO date format using named or numbered groups.

Input

(\d{4})-(\d{2})-(\d{2})

Output

Input "2024-03-15" → Group 1: "2024", Group 2: "03", Group 3: "15"

Match email-like patterns

A simplified email pattern (not RFC 5322 compliant, but catches obvious non-emails).

Input

[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}

Output

Matches "user@example.com", "first.last+tag@sub.domain.org"

Limitations

  • Uses JavaScript regex engine only. Patterns using PCRE-specific features (lookahead with variable length, recursive patterns, possessive quantifiers) may not work.
  • Does not support regex flavors from other languages (Python re, Java Pattern, .NET Regex). Flags and syntax may differ.
  • Cannot test regex replacement (substitution) — only matching and group extraction are supported.
  • Very complex patterns with catastrophic backtracking may freeze the browser. No timeout protection is applied.

Features

  • Real-time matching: results update as you type, no submit button
  • All JavaScript flags supported (g, i, m, s, u, v, y)
  • Capture group display with numbered groups
  • Syntax error highlighting with descriptive messages
  • Match count and position indicators
  • Your data stays local. Nothing sent anywhere

Frequently Asked Questions

Why does my regex work in Python but not here?

Different regex flavors. Python uses PCRE-like syntax with features JavaScript lacks: lookbehind (added in ES2018, not in older browsers), atomic groups, possessive quantifiers (a++), verbose mode (x flag), and \A/\Z anchors. If your pattern uses these, you'll need to rewrite for JavaScript. Most common issue: Python's re.DOTALL is JavaScript's s flag.

How do I match across multiple lines?

Two options: (1) Add the s flag, which makes . match newline characters (\n). (2) Use [\s\S] instead of ., which matches any character including newlines without needing the s flag. For matching line-by-line, use the m flag so ^ and $ match line boundaries.

What's the difference between (?: ) and ( )?

( ) is a capturing group that captures the matched text for later use (backreferences, extraction). (?: ) is a non-capturing group that groups the pattern for quantifiers or alternation but doesn't capture. Use (?: ) when you need grouping but don't need the captured value. It's slightly faster and keeps your group numbering clean.

Why is my regex making the page freeze?

Catastrophic backtracking. Patterns with nested quantifiers on overlapping characters (like (a*)*b or (.+)+$) can take exponential time on non-matching inputs. The engine tries every possible combination before giving up. Fix: make quantifiers more specific, use atomic groups (not in JS), or restructure to avoid nesting quantifiers on the same characters.

How do I match special characters literally?

Escape them with a backslash: \. for dot, \* for asterisk, \( for parenthesis, \\ for backslash itself. Inside a character class [ ], most special characters lose their meaning except ] \ ^ -. When in doubt, escape it. An unnecessary escape is harmless, a missing one is a bug.

Is it safe to test regex patterns against sensitive text here?

Yes. All regex evaluation uses the browser's native JavaScript RegExp engine. Your test strings never leave your device. No data is sent to our servers at any point. You can test against real log lines, PII-containing text, or production data without concern. Verify in DevTools → Network: zero outbound requests when you run a match.

Last reviewed:

Your Privacy

All regex testing happens entirely in your browser. No data is uploaded to any server. Your patterns and test strings never leave your device.

In-Depth Guide

Regex Cheat Sheet: Patterns Every Developer Needs

The regex patterns you actually use at work: email validation, URL parsing, password rules, with explanations of why they work and where they break.

Read guide

Tips & Related Workflows