toolgarden.xyz
中文

Regex Tester

Free online regular expression tester with flags, named groups, highlighted matches and common templates

Regular expression

//g

Test text

联系我们: hello@example.com, sales@toolgarden.xyz

Matches

2 matches

  • #1Index: 6

    hello@example.com

  • #2Index: 25

    sales@toolgarden.xyz

About this tool

A regular expression describes matching locations in text. The tester uses the browser JavaScript RegExp engine with common flags, named groups, global matching, and highlighting, plus editable starting patterns for common shapes such as email, URLs, and numbers.

Regex is useful for local text patterns, not as a universal parser. Nested syntax, complete HTML, variable date dialects, and natural language usually need dedicated parsers. Overly broad expressions or catastrophic backtracking can also stall on long text.

How to use it

  1. Enter the pattern and flags

    Do not include host-language slash delimiters. Enable g, i, m, s, u, or y only when their behavior is needed.

  2. Add representative test text

    Include positive examples, boundary cases, and values that must not match instead of testing success alone.

  3. Review highlights and groups

    Check match count, complete spans, and capture groups, then preserve the same flags in destination code.

Input and output example

Named groups let you read results by name instead of remembering which bracket was which.

Pattern and test text
/(?<year>\d{4})-(?<month>\d{2})/g

Effective 2026-08, expires 2027-01
Matches
Match 1: 2026-08   year=2026  month=08
Match 2: 2027-01   year=2027  month=01

Supported range and limits

Regex dialect
JavaScript RegExp. Parts of Python, PCRE and Java syntax do not apply here
Supported flags
g global, i case-insensitive, m multiline, s dotall, u Unicode, y sticky
Named groups
(?<name>...) named capture is supported and shown by name in the results
Not supported
Recursion, conditionals, and some PCRE-only assertion forms
Performance trap
Nested quantifiers such as (a+)+ cause catastrophic backtracking on long non-matching input and can freeze the page
Where it runs
Executed with the browser's native RegExp; your test text is never uploaded

When you would use it

  • Cleaning logs and lists

    Locate timestamps, IDs, blank lines, or fixed prefixes before extracting or replacing them in code.

  • Checking an input shape

    Perform a quick client-side check for a stable identifier, path, or tag format with limited rules.

  • Reproducing a match failure from production

    When a live regex misses or over-matches, paste the real input and adjust it here; far quicker than editing code and redeploying.

What to know before you start

  • JavaScript regex syntax and features differ from PCRE, Python, and Java. Retest before moving a pattern across languages.
  • Without the g flag, a search normally returns only the first match. Use global mode when all results matter.
  • Do not parse complete HTML, XML, or a programming language with one large regex; a structural parser is safer.

Related concepts

capture group
A parenthesized part of a match retained for extraction or replacement; named groups are addressed by name.
catastrophic backtracking
An exponential search caused by certain nested repetitions and alternatives, consuming heavy CPU on crafted input.

Frequently asked questions

Does the regex tester upload my text?
No. Matching runs locally in your browser, so your test text is never uploaded.
Which flags and groups are supported?
It supports common flags like g, i, m and s plus named capture groups, and highlights every match in your text.
Are there ready-made regex templates?
Yes. Built-in templates for email, URL, phone numbers and more can be applied in one click and then tweaked.
My regex works in Python but not here; why?
This runs JavaScript's RegExp. Python's `(?P<name>...)` named groups, some assertion forms, and PCRE-only recursion either use different syntax or do not exist in JavaScript. Porting a regex means adapting it to the target dialect.
Why did the page freeze?
Most likely catastrophic backtracking. A nested quantifier such as `(a+)+` on long non-matching input makes the backtracking count grow exponentially. Avoid nested quantifiers, use more specific character classes, or anchor the match explicitly.