Regex Explainer
你要匹配什么未匹配模板
测试串
生成的正则
自定义与替换
多字段脱敏批量字段
选中的字段会一次性脱敏,命中区间不重叠;可直接导出对照表。
逐段解释
How to Use
📖 What it does
Regex costs more time in revision than in writing: one missing escape and nothing matches, one greedy quantifier and it swallows the next line. This tool distils common needs into ten templates, each with the pattern, a segment-by-segment reading and a sample string, then previews matches on your real data.
Nothing is sent anywhere and no model is called; templates and explanations ship with the plugin, and the preview runs the browser's native regex engine.
A global match over 5,000 characters with highlighting finishes in about 4 ms, recalculated on every edit.
Matches are stored as position pairs and HTML is built only at render time, with a 500-hit guard against zero-width loops.
The workspace exposes 16 controls, from 用中文描述需求,或直接点下面的模板 to 保留后 M 位, and every one of them only affects the local rendering: nothing is sent back to a server.
Ranges and defaults: 脱敏策略 (按字段类型自动保留 / 统一保留前 N 后 M / 全部替换为掩码字符 / 替换为类型标签), 掩码字符 (* / • / X / #). Values outside the slider range are rejected rather than silently clamped.
The 用中文描述需求,或直接点下面的模板 control takes free text and feeds it straight into the preview without sending it anywhere.
The 全局 g control toggles a single behaviour on or off; the preview updates at once and the exported file follows the current state.
The 忽略大小写 i control toggles a single behaviour on or off; the preview updates at once and the exported file follows the current state.
The 多行 m control toggles a single behaviour on or off; the preview updates at once and the exported file follows the current state.
The 点匹配换行 s control toggles a single behaviour on or off; the preview updates at once and the exported file follows the current state.
✨ Features
- Ten templates: mobile, landline, email, URL, date, ID card, IPv4, CJK text, amount and strong password.
- Keywords route to templates: typing phone, email or date selects the matching template automatically.
- Segment explanations: the pattern is split into pieces with one line per piece, so \d{9} is no longer a guess.
- Match preview: matched spans are highlighted, with counts for hits and matched characters.
- Flag switches: g, i and m are reflected in the pattern suffix and recalculated instantly.
- Safe execution: invalid patterns report an error instead of freezing, and empty matches are capped at 500.
🚀 How to use
- Type the need in the description box, such as match email, or click a template chip.
- Toggle global, case-insensitive and multiline flags and watch the suffix change.
- Read the segment list on the right to confirm each group means what you intended.
- Paste real data into the test area and check the highlighted spans.
- Copy the pattern into code, remembering to escape backslashes again inside strings.
⚠️ Before you rely on it
- Mostly unanchored: templates omit ^ and $ so they find matches inside text; add anchors for whole-string validation.
- Mainland mobile only: leading 1, second digit 3 to 9, eleven digits; no international or HK/Macau/Taiwan numbers.
- No checksum: the ID template validates the birth date segment only; authenticity needs the weighted checksum.
- Lookaheads do not consume: several (?=...) assertions let one pattern require letters and digits at once.
- Escape twice in strings: a backslash in a JS string literal must be doubled or it disappears.
- Greedy by design: the URL template stops only at whitespace, quotes or angle brackets.
- Interface copy follows the site language; there is no in-plugin switch.
- Descriptions and test data stay in this browser and are never stored.
Questions people ask: Q: Why does the mobile pattern miss longer numbers? A: It encodes mainland eleven-digit mobiles starting with 1 and a second digit from 3 to 9; international numbers need another template. Q: Why does the preview differ from my code? A: Usually the flags differ or backslashes were eaten in a string literal. Align g/i/m first, then check escaping. Q: Can I use it for server-side validation? A: Yes, but add anchors and length limits, and mind dialect differences between JS and PCRE. Q: The copied pattern fails to compile in my code. Why? A: The preview follows JavaScript syntax and the exported text has no /.../gi wrapper; adapt grouping and escaping when moving to Python or PCRE. Q: The Chinese template does not match in another engine. A: The pattern uses the common CJK range; engines that reject that range need an explicit character set instead. Q: Can a heavy pattern freeze it? A: Templates stay within two or three groups. Very long custom patterns can still backtrack badly, so try them on a small sample first.
Typical use: A form needs a phone or ID pattern and you do not want to dig through old projects. Pulling every URL or email out of a log before changing code. Inheriting someone's regex and needing a readable breakdown before editing it.
What you can enter: A description or a template choice, either one is enough. Test text is optional and only used for the preview.
What you get back: The pattern with its flags and a segment-by-segment explanation. Match stats: hit count, matched characters and the active flags.
Limits to keep in mind: Templates and explanations only; no free-form generation of arbitrary complex patterns. No ReDoS risk assessment; nested quantifiers still need your own stress tests. The ID template skips the checksum and mobiles exclude international numbers.