UFOZoo

Regex Tester — JavaScript & PCRE Pattern Debugger Tool

Test regex patterns with real-time match highlighting, capture groups visualization, and replacement testing. Supports JavaScript and PCRE flavors.

Features

  • Real-time match highlighting — see matches light up instantly as you type your pattern or test string
  • Capture groups visualization — all numbered and named groups displayed with their matched content in a structured table
  • Detailed match information for each match including exact position (index), length, and full match text
  • Regex flag toggles — switch between global (g), case-insensitive (i), multiline (m), dotAll (s), and Unicode (u) modes with one click
  • Replacement testing mode — test your replace patterns with $1, $2 back-references and see the result in real time
  • Common regex library — one-click load pre-built patterns for email, URL, phone number, IP address, date, password validation, and more
  • Syntax error detection with clear, human-readable error messages when your regex is invalid
  • Match count statistics — total matches found, total capture groups, and processing time displayed in the status bar
  • One-click copy pattern or matches to clipboard for quick sharing with teammates
  • Full JavaScript RegExp engine compatibility — uses the browser's native engine so results are identical to your production code
  • Entirely client-side processing — zero data transmission, works offline after initial load, perfect for sensitive data like passwords or PII

How to Use

  1. 1Enter your regular expression pattern in the "Pattern" field at the top. Use forward slashes (/pattern/) or enter the raw pattern without delimiters.
  2. 2Toggle the flags below the pattern field: g (global — find all matches), i (case-insensitive), m (multiline — ^$ match line boundaries), s (dotAll — dot matches newlines), u (Unicode — full Unicode support).
  3. 3Paste or type your test string in the input area below. Matches highlight automatically as you type.
  4. 4View detailed match information in the right panel: each match shows its position, length, captured groups, and the full matched text.
  5. 5Switch to Replace mode to test substitution patterns. Enter your replacement string with $1, $2 references to use capture groups.
  6. 6Click any preset pattern from the Common Patterns library to quickly load frequently-used regexes like email validation or URL matching.
  7. 7Copy the pattern or results using the toolbar buttons. Download matches as a text file if needed.
  8. 8Use the Regex Explanation panel to break down complex patterns — each token is explained in plain English to help you understand what your regex does.

Frequently Asked Questions

What is a regular expression (regex)?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. It's used for finding, replacing, validating, and extracting text based on pattern rules. For example, `\d{3}-\d{4}` matches phone number patterns like "555-1234". Regex is supported in almost every programming language (JavaScript, Python, Java, PHP, Go, Rust) and text editor (VS Code, Sublime Text). This tool uses JavaScript's native RegExp engine, so results match exactly what your JS code produces.

What do the regex flags mean?

Flags modify how the regex engine behaves: • **g (Global)**: Find all matches instead of stopping after the first one • **i (Case-insensitive)**: Match uppercase and lowercase letters interchangeably — /hello/i matches "Hello", "HELLO", "hello" • **m (Multiline)**: Make ^ and $ match the start/end of each line instead of the entire string • **s (dotAll / Single-line)**: Make . (dot) match newline characters too, not just non-newline characters • **u (Unicode)**: Enable full Unicode support including emoji, CJK characters, and Unicode property escapes like \p{Script=Han}

How do capture groups work?

Capture groups are parts of your regex enclosed in parentheses (...) that extract specific portions of each match. For example, `(\d{3})-(\d{4})` in "555-1234" creates two groups: Group 1 = "555", Group 2 = "1234". You can name groups with `(?<name>...)` syntax for easier reference: `(?<area>\d{3})-(?<number>\d{4})`. In replacement strings, refer to groups as $1, $2 (numbered) or $<name> (named). Non-capturing groups `(?:...)` group without capturing — use them when you need grouping logic but don't need the extracted value.

Why does my regex show as invalid?

Common causes of invalid regex: unescaped special characters (use \\ for literal backslash, \. for literal dot), mismatched parentheses (every opening ( needs a closing)), invalid quantifier placement (cannot put + after a group that doesn't exist), or unsupported syntax in JavaScript (lookbehinds require fixed width, recursive patterns aren't supported). The error message shows exactly where the parser failed — look for the red error indicator near the problematic character. Tip: start simple, add complexity gradually, and test after each change.

Does this support PCRE or Python regex?

This tool uses JavaScript's native RegExp engine (ECMAScript standard). It covers most common regex syntax shared across languages: character classes (\d, \w, \s), quantifiers (*, +, ?, {n,m}), anchors (^, $, \b), lookaheads ((?=...), (?!...)), and named capture groups. However, some features differ: Python's recursion ((?R)) isn't available, PCRE's conditional patterns ((?ifthen|else)) don't work, and possessive quantifiers (x++ JS 2024+) have limited support. For language-specific testing, check our tool output against your target runtime — the native engine ensures accuracy for JavaScript/TypeScript projects.

Is my test data sent to a server?

No. All regex matching, highlighting, and processing happen entirely in your browser using JavaScript's built-in RegExp object. Your patterns, test strings, and matched results never leave your device — there's no backend server, no API calls, no data collection. You can even disconnect from the internet after the page loads and it will continue working perfectly. This makes it safe to test with sensitive data like passwords, API keys, personal information, or confidential logs.

How does replacement mode work?

In replacement mode, you provide a replacement string that uses special syntax to reference capture groups: • `$&` or `$0` — the entire match • `$1`, `$2`, `$3` — numbered capture groups (1-indexed) • `$<name>` — named capture groups (ES2018+) • `` $` `` — everything before the match • `$'` — everything after the match • `$$` — literal dollar sign For example, pattern `(\w+)@(\w+)` with replacement `$2@$1` swaps the parts around each @ symbol. Test complex replacements here before deploying to production.

Can I test regex performance or detect catastrophic backtracking?

The tool displays processing time for each match operation. If you notice extreme slowdown (seconds instead of milliseconds) with certain inputs, you may have encountered catastrophic backtracking — a situation where the regex engine explores exponentially many possibilities before failing. Common triggers: nested quantifiers like `(a+)+`, overlapping alternation, and quantifiers on optional groups. To diagnose: simplify your pattern, use atomic groups or possessive quantifiers where available, or restructure to avoid ambiguous branching. The real-time feedback helps catch performance issues before they hit production.

What is the difference between greedy and lazy quantifiers?

Greedy quantifiers (*, +, {n,}) match as much as possible. Lazy quantifiers (*?, +?, {n,}?) match as little as possible. For example, on 'abc123': /\w+\d+/ matches 'abc123' (greedy, eats all), while /\w+?\d+/ matches 'abc1' (lazy, takes minimum before \d+). Use lazy quantifiers to avoid matching too much.

How do I match Unicode characters including emoji with regex?

Use the 'u' (Unicode) flag and Unicode property escapes. For example: \p{Emoji} matches any emoji, \p{Script=Han} matches Chinese characters, \p{L} matches any Unicode letter. Without the 'u' flag, \d and \w only match ASCII characters. With the 'u' flag, they match full Unicode.

Related Tools