🧪

Regex Tester

Build and test regular expressions live with match highlighting, capture groups, and replace mode.

//
Presets:

Test text

0 matches

Replace

Click "Show" to test pattern replacement.

Cheatsheet

\dAny digit (0-9)
\DAny non-digit
\wWord character [A-Za-z0-9_]
\WNon-word character
\sWhitespace
\SNon-whitespace
.Any character (except newline)
^Start of string / line
$End of string / line
*0 or more
+1 or more
?0 or 1 (or non-greedy)
{n,m}Between n and m times
[abc]Any of a, b, c
[^abc]None of a, b, c
(...)Capturing group
(?:...)Non-capturing group
(?<name>...)Named group
|OR alternation

About this tool

A fast, browser-based JavaScript regex tester. Type a pattern and see live match highlighting on your test text. Toggle flags, run replace operations, and explore preset patterns for email, URL, phone number, and IP address validation.

🎯Live match highlighting as you type
🚩Toggle all common flags (g, i, m, s, u, y)
🔄Replace mode with capture group support ($1, $2, …)
Preset patterns for email, URL, phone, IP, hex
📚Built-in regex cheatsheet
🛡️Runs locally — no patterns logged

How to use it

Quick steps to get the most out of this utility.

  1. 1

    Enter your pattern

    Type a regex pattern. Use the flag input on the right to toggle global, case-insensitive, multiline, etc.

  2. 2

    Paste test text

    Drop in the text you want to match against. Matches are highlighted instantly.

  3. 3

    Use a preset

    For common patterns like email or URL validation, click a preset to load a battle-tested regex.

  4. 4

    Try replace

    Switch to Replace mode to see how the pattern would substitute matches in your text.

A practical mental model for regex

Think of a regex as a tiny program that walks through text looking for patterns. Each character in the pattern either matches itself literally (most letters and digits) or has a special meaning (the metacharacters). The engine tries to match starting from each position, backtracking when needed.

The hardest part of regex isn't the syntax — it's knowing when to stop. A pattern that matches 80% of cases on Stack Overflow probably still misses 20%. Validating email addresses with regex is a famous example: the official RFC 5322 regex is over 6,000 characters long. For most use cases, a “good enough” pattern that matches typical formats is the right answer.

When NOT to use regex

  • Parsing HTML, XML, or JSON — use a real parser.
  • Validating email addresses strictly to spec — accept the 80% solution and verify by sending an actual email.
  • Date and number parsing where format varies — use a date library or numeric parser.
  • Anything that needs to handle nested structures — regex cannot do recursion in JavaScript.

Frequently asked questions

What regex flavor does this support?+

JavaScript regex (ECMAScript). Most regex syntax is portable across languages, but a few features differ — for example, JavaScript named groups use (?<name>...), while some other languages use (?P<name>...).

Why isn't my pattern matching?+

Common reasons: the pattern is case-sensitive but your text is mixed case (add the i flag), or the pattern matches across lines but you forgot the m flag, or you have unescaped special characters (escape with \).

How do capture groups work?+

Parentheses ( ) create a capture group. The matched text inside is captured separately and can be referenced in the replacement as $1, $2, etc. For named groups, use (?<name>pattern) and reference as $<name> in JavaScript replace.

Should I use regex to parse HTML?+

No. HTML has nested structures and edge cases that regex cannot reliably handle. Use a real HTML parser like DOMParser in browsers, BeautifulSoup in Python, or jsdom in Node.

What's the difference between greedy and lazy matching?+

By default, quantifiers like * and + are greedy — they match as much as possible. Adding ? after them (*? or +?) makes them lazy — they match as little as possible. Lazy matching is essential for things like extracting content between two delimiters.

Keep exploring

More utilities and reading from Toolisk.