Regex Tester & Debugger

Regex Tester

Test, debug, and inspect JavaScript regular expressions in real time with live highlighted matches, numbered and named capturing group breakdown, character index ranges, and string substitution. Run common regex patterns or build custom expressions safely in your browser.

Regular Expression & Flags JavaScript / ECMAScript Engine
Popular Regex Presets
Test String & Live Match Highlighting 147 characters • 4 lines
Match & Group Inspector
Matches Found
4 Matches
Execution: 0.4 ms
Flags: /gm

Regular Expression Syntax Quick Reference

Common tokens, quantifiers, anchors, and lookaround assertions supported by the ECMAScript JavaScript regex engine.

Character Classes . Any char except newline
\d Digit [0-9] | \D Non-digit
\w Word char [a-zA-Z0-9_]
\s Whitespace | \S Non-space
[a-z] Character range
[^a-z] Negated set
Quantifiers * 0 or more (greedy)
+ 1 or more (greedy)
? 0 or 1 (optional)
{n} Exactly n times
{n,m} Between n and m times
*?, +? Lazy quantifiers
Anchors & Boundaries ^ Start of string or line (with /m)
$ End of string or line (with /m)
\b Word boundary
\B Non-word boundary
| Alternation (OR operator)
Groups & Lookaround (abc) Capturing group
(?<name>abc) Named group
(?:abc) Non-capturing group
(?=abc) Positive lookahead
(?!abc) Negative lookahead
(?<=abc) Positive lookbehind

How Regular Expressions Work in JavaScript

A regular expression (regex) is a sequence of characters that specifies a search pattern in text. In JavaScript, regular expressions are created either with literal syntax between forward slashes (such as /pattern/flags) or via the new RegExp('pattern', 'flags') constructor. This tool runs directly inside your browser's V8 JavaScript engine, ensuring that all match indices, capturing groups, and substitution operators behave identically to your production code.

Common Regex Use Cases

  • Input Validation: Verifying email formats, phone numbers, ZIP codes, and passwords before submitting web forms.
  • Data Extraction: Parsing log files, web scraper HTML content, and financial statements to extract dates, IP addresses, and monetary amounts.
  • String Masking & Formatting: Reformatting phone numbers ((512) 555-0198), redacting sensitive Social Security numbers, or converting snake_case into camelCase.

Frequently Asked Questions

What does the "g" (global) flag do?

Without the g flag, a regular expression stops evaluating after finding the very first match in the text. With the g flag enabled, the regex searches through the entire input string to return all matching occurrences.

How do capturing groups work?

Parentheses (...) create capturing groups that extract sub-portions of your match. In JavaScript, group 0 ($&) represents the full match, $1 is the first group, $2 is the second, and so on. You can also name groups using (?<name>...) and reference them with $<name> in replacement strings.

What is the difference between greedy and lazy quantifiers?

Standard quantifiers like *, +, and {n,m} are greedy: they match as many characters as possible. Adding a question mark (*? or +?) makes them lazy, meaning they match the fewest characters necessary to satisfy the expression.

Is my test data uploaded to any server?

No. All regex compilation, pattern matching, syntax highlighting, and text substitution run 100% locally inside your web browser. None of your test text or sensitive data ever leaves your device.