Developer Tools
正则测试器
正则不匹配却看不出原因?粘贴模式与测试字符串——匹配会实时亮起,方便调试。
Flags
Common patterns
Regex cheatsheet
Character classes
- .
- Any character except newline
- \d / \D
- Digit / non-digit
- \w / \W
- Word char (A-Za-z0-9_) / non-word
- \s / \S
- Whitespace / non-whitespace
- [abc]
- Any of a, b, c
- [^abc]
- Anything except a, b, c
- [a-z]
- Range a through z
Quantifiers
- *
- 0 or more (greedy)
- +
- 1 or more (greedy)
- ?
- 0 or 1
- {n}
- Exactly n
- {n,}
- n or more
- {n,m}
- Between n and m
- *? +? ??
- Lazy versions: match as little as possible
Anchors
- ^
- Start of string (or line with m flag)
- $
- End of string (or line with m flag)
- \b
- Word boundary
- \B
- Not a word boundary
Groups
- (abc)
- Capture group: numbered 1, 2, 3…
- (?:abc)
- Non-capturing group
- (?<name>abc)
- Named capture group
- a|b
- Alternation: a or b
- \1
- Backreference to group 1
- (?=abc)
- Positive lookahead
- (?!abc)
- Negative lookahead
Private by design: This tool runs entirely in your browser. Nothing you type or upload is sent to a server.
使用方法 正则测试器
- 输入模式. 输入不带斜杠的正则,按需开关标志位(g、i、m、s、u)。
- 添加测试文本. 粘贴要匹配的字符串——日志、表单输入,什么都行。
- 检查匹配. 匹配在文本中高亮,下方面板列出每个匹配及其捕获组。
- 试试预设. 卡住了?加载常用模式(邮箱、URL、日期…)再改。
正则测试器 功能
- 实时匹配高亮
- 每个匹配的捕获组列表
- 标志位开关(g i m s u y)
- 常用模式预设
- 内置正则速查表
- 清晰的无效模式报错
正则测试器 常见问题
- JavaScript(和您的浏览器同款引擎)。多数语法可迁移到 Python、Java、PCRE,但后行断言和一些高级特性在不同风格间有差异——务必在目标语言中重新测试。
- 报错信息会显示浏览器的确切抱怨——通常是未闭合的括号、多余的反斜杠或错误的量词。在模式框中修复,高亮即时恢复。
- g(全局)找到所有匹配而非停在第一个;m(多行)让 ^ 和 $ 匹配行边界而非仅字符串起止。两者独立——通常两个都要。
- 括号创建编号组。每个匹配行展开显示组 1、2、3…及其捕获文本——不需要值时用 (?:…) 表示非捕获组。
- 在这个测试器里,失控的模式最多让标签页短暂卡住——需要时关掉即可。生产代码中避免 (a+)+ 这类嵌套量词,目标风格支持的话优先用原子组或占有量词。
相关工具
UUID Generator
Generate bulk v4 UUIDs with Web Crypto - uppercase/lowercase, hyphens on/off, copy all.
Use tool →Password Generator
Generate strong random passwords with Web Crypto - length, character sets, entropy meter.
Use tool →Case Converter
Convert text between UPPER, lower, Title, camelCase, snake_case, kebab-case and more.
Use tool →