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.
Flags
Character Classes
.Any character\dDigit (0-9)\wWord character\sWhitespace
Quantifiers
*0 or more+1 or more?0 or 1{n,m}n to m times
Anchors
^Start of line$End of line\bWord boundary\BNon-word boundary
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
- Enter your regex pattern — no delimiters needed (just the pattern, not /pattern/).
- Set flags: g (all matches), i (case-insensitive), m (multiline), s (dot matches newline).
- Paste your test string. Matches highlight in real time.
- Check 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
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.
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.
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.
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 "[email protected]", "[email protected]"Features
- Real-time matching — results update as you type, no submit button
- All JavaScript flags: g, i, m, s, u, v, y
- Capture group display with numbered groups
- Syntax error highlighting with descriptive messages
- Match count and position indicators
- Runs 100% in your browser — no data 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 — this makes . match newline characters (\n). (2) Use [\s\S] instead of . — this 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 — it captures the matched text for later use (backreferences, extraction). (?: ) is a non-capturing group — it 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.
Tips & Related Workflows
- Test your regex against JSON data? Format it first with our JSON Formatter.
- Need to hash matched text for verification? Use our Hash Generator.
- Encode regex-matched URLs safely with our URL Encoder/Decoder.
- Working with Base64-encoded strings in your regex? Decode them with our Base64 Encoder/Decoder.