正则表达式测试工具
用实时高亮测试正则表达式,列出每一处匹配、位置和捕获组。
Common flags
| Flag | Meaning |
|---|---|
g | Global — find all matches, not just the first |
i | Case-insensitive |
m | Multiline — ^ and $ match at line boundaries |
s | Dotall — . also matches newlines |
u | Unicode — enable full Unicode support (needed for \p{...}) |
y | Sticky — match only at the last successful position |
Useful patterns
# Email (pragmatic, not RFC-complete)
[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}
# ISO date
\d{4}-\d{2}-\d{2}
# Hex colour
#(?:[0-9a-fA-F]{3}){1,2}\b
# IPv4
(?:\d{1,3}\.){3}\d{1,3}
# URL
https?:\/\/[^\s/$.?#].[^\s]*
# Named capture group
(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})
Performance warning
Catastrophic backtracking is real. A pattern like (a+)+$ against a long run of a characters followed by a non-matching character can hang the browser for minutes. When a regex feels slow, look for nested quantifiers — a + or * inside a group that is itself quantified.
If you need a timeout or progress reporting for complex patterns, run the matching in a Web Worker so the UI stays responsive.
Related
Working with structured data instead? The JSON formatter validates and beautifies payloads.
常见问题
Is my text uploaded anywhere?
No. The pattern is compiled and matched in your browser.
What do the flags mean?
g for global, i for case-insensitive, m for multiline, s for dot-matches-newline, u for full Unicode, and y for sticky matching.
Why does my regex hang the browser?
Almost always catastrophic backtracking. Look for nested quantifiers — a + or * inside a group that is itself quantified — and rewrite them to be unambiguous.
What is the difference between a capture group and a named one?
A capture group is referenced by number, (...) as $1. A named group, (?<name>...), is referenced by name, which is far easier to maintain in a large pattern.
Can I use it to test a pattern against a huge file?
It is designed for snippets. For large files, use a dedicated tool such as grep with -P, or ripgrep.