Skip to content
UniKit

Regex tester

Test regular expressions online: highlight matches, list capture groups (named groups included), preview $1 replacements, toggle the g/i/m/s/u/y/d flags, measure match count and timing, and see the position of invalid patterns — with email/URL/phone/IP/date presets.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Presets

Flags

Without the g flag only the first match is used; the replacement preview uses the same flags.

Highlighted matches

Matches: 2

联系 alice@example.com 或 bob@test.cn,电话 13800138000,时间 2026-10-10。

Match details

#PositionMatch
13–20alice@example.com
223–34bob@test.cn

Capture groups

GroupNameValue
1useralice
2domainexample.com

Replaced text

联系 [alice] 或 [bob],电话 13800138000,时间 2026-10-10。

What this tool does

  • Iterate on a pattern with instant feedback: matches are highlighted and the count, positions and elapsed time update as you type.
  • Need to extract parts of a match? The capture group panel lists numbered and named groups so you can see exactly which text $1 or $<name> refers to.
  • Preview a bulk replacement before shipping it: enter a template and check the result text to confirm group order and escaping.
  • Unsure whether to enable g, m, s or u? Toggle them one at a time — the difference is obvious with pasted logs, multi-line text or emoji.

Example

Input

Pattern (?<user>[\w.+-]+)@(?<domain>[\w-]+\.[\w.]+), flag g, text "联系 alice@example.com 或 support@example.com", replacement [$<user>]

Output

2 matches: alice@example.com (user=alice, domain=example.com) and support@example.com (user=support, domain=example.com); replaced text "联系 [alice] 或 [support]"

Without the g flag only the first match is used; the replacement preview uses the same flags as the matching, so both occurrences are replaced here.

Frequently asked questions

Why does my pattern only match once?

The g flag is off. Without it exec returns just the first match and the replacement only touches the first occurrence. Turn on global matching when processing logs or doing bulk replacements — and note that y is sticky matching, which means something quite different.

What happens when the pattern is invalid?

You get an error type plus a guessed character position — a missing closing parenthesis, for example, points at the corresponding opening one. The position comes from tracking bracket pairs, character classes and quantifier syntax, so treat it as a locating hint rather than an authoritative engine error.

Are long texts or huge match counts limited?

Yes. The test text is capped at 200,000 characters and matches at 2,000; going past either reports the limit and stops, so a pathological pattern cannot hang the tab. It is a safety valve, not a problem with your regex.

What is the difference between $1 and $<name>?

$1 references the first capture group by number, while $<name> references a named group, which requires (?<name>…) in the pattern. Numbered references shift when groups are added or removed, so named groups are safer for templates you keep around.

Is my test text uploaded?

No. Matching, replacing and highlighting all run in the browser with JavaScript regex, no request is made, and pasted logs never leave your machine.

Keywords:regexregexp正则正则表达式正则测试regex testercapture group捕获组replace

Related tools