Regex Tester · RegexLens

Test regular expressions with live-highlighted matches.

Updated:

100% client-side
/ /g

Test text

0 characters

Highlighted result

—

What the regex tester does

A regular expression (regex) is a compact pattern used to find or validate pieces of text, like email addresses or phone numbers, inside a larger block of text. RegexLens lets you test a regex pattern against real sample text and see, live, exactly which parts it matches — highlighted in place — plus the contents of any capture groups, so you can check and debug a pattern before using it in code.

How to use the regex tester

  1. Type or paste a regex pattern into the field at the top (or click Example to load a sample), and toggle any flags (g, i, m, s, u) you need.
  2. Paste the text you want to test against into the Test text panel.
  3. Check the Highlighted result panel: every match is highlighted directly in your text, with capture groups listed below.
  4. Adjust the pattern or flags and watch the highlighting update live until it matches what you expect.

How regular expressions work

A regular expression (regex) describes a text pattern using a compact syntax: character classes, quantifiers and capture groups. The engine scans the test text looking for fragments that match that pattern:

Pattern: /(\w+)@(\w+\.\w+)/g
Text:    "Contacts: ada@lovelace.dev, bob@example.com"
Match 1: "ada@lovelace.dev"     group 1: "ada"   group 2: "lovelace.dev"
Match 2: "bob@example.com"      group 1: "bob"   group 2: "example.com"

This tool uses JavaScript's native RegExp object with matchAll — no external libraries, no server calls.

Examples

1. Find email addresses in text. With the g flag on, every match is listed with its position. Note that user@localhost is skipped because the pattern requires a dot in the domain:

Pattern: [\w.+-]+@[\w-]+\.[\w.]+    Flags: g
Text:    Contact ana.ruiz@example.com or support+billing@shop.co.uk — not user@localhost.

2 matches
Match 1 — "ana.ruiz@example.com" (index 8)
Match 2 — "support+billing@shop.co.uk" (index 32)

2. Pull dates apart with named groups. (?<name>…) labels each capture, so the groups panel shows year, month and day next to the numbered groups — the same names you would read from match.groups in JavaScript:

Pattern: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Text:    Released 2026-03-14, patched 2026-04-02.

Match 1 — "2026-03-14" (index 9)   year: 2026  month: 03  day: 14
Match 2 — "2026-04-02" (index 29)  year: 2026  month: 04  day: 02

3. Greedy vs. lazy quantifiers. .+ grabs as much as it can, so <.+> swallows the whole line as one match. Adding ? makes it lazy and it stops at the first >:

Text: <b>bold</b> and <i>italic</i>

<.+>   → 1 match:  "<b>bold</b> and <i>italic</i>"
<.+?>  → 4 matches: "<b>"  "</b>"  "<i>"  "</i>"

Common regex mistakes and how to fix them

  • Not escaping the dot. An unescaped . matches any character. Against version 2.5 and build 2026-11, the pattern \d+.\d+ finds two matches — 2.5 and 2026-11 — while \d+\.\d+ finds only 2.5.
  • Forgetting the g flag. Without it, JavaScript stops at the first match: String.replace replaces only one occurrence and matchAll throws a TypeError. Turn g off here and the match count drops to 1, which is what your code will see.
  • Greedy quantifiers eating too much. As in example 3, .* and .+ run to the last possible delimiter. Use the lazy form (.*?) or a negated class such as <[^>]+>, which is also faster.
  • Anchors on multi-line text. ^ and $ match only at the very start and end of the whole input unless the m flag is on; with it, they match at every line. A pattern that "works on one line but not on the pasted file" is usually missing m.
  • Catastrophic backtracking. Nested quantifiers like (a+)+$ or (\w+\s?)*$ can take exponential time on a string that almost matches, freezing the page or a server (a ReDoS). This tester cuts off a match that runs too long and reports Matching timed out instead of hanging; your production code gets no such guard. Remove the nesting, make the inner part unambiguous, or anchor it.
  • Unclosed groups. (abc is rejected with Invalid regular expression: /(abc/g: Unterminated group. Count your parentheses, and escape literal ones as \( and \).

Regex tester vs. other ways to test a pattern

This tester runs your pattern in the browser's own JavaScript engine, so what you see is exactly what new RegExp() does in Node.js or any browser. Other languages use other engines: Python's re, PCRE (PHP, grep -P) and Go's RE2 differ in details such as lookbehind support, named-group syntax ((?P<name>…) in Python) and Unicode classes. For a pattern bound for those, test the final version where it will run, for example grep -E 'pattern' file.txt or python -c "import re; print(re.findall(r'pattern', text))". To understand a long pattern you inherited, paste it into the Regex Visualizer to see it as a railroad diagram. The full syntax is documented in MDN's regular expressions guide.

Frequently asked questions

What regex engine does it use?

The browser's native JavaScript RegExp engine, the same one you'd use with .match() or .test() in your code — no conversion to another dialect (like PHP's PCRE or Python's).

What flags can I use?

g (global), i (case-insensitive), m (multiline), s (dot also matches newlines) and u (unicode) — toggled with checkboxes.

Does it show capture groups?

Yes, each match lists its numbered and named groups (if you use (?<name>...)) separately, with their exact text. If you want a structure diagram and plain-English explanation of the pattern itself instead of live match testing, use Regex Visualizer.

What happens if my regex has a syntax error?

It shows the exact error message the browser's engine returns, as soon as you stop typing.