🧪 正则测试器Regex Tester
实时测试正则表达式:高亮所有匹配、显示匹配数量与每一处捕获组。支持 i(忽略大小写)、m(多行)、s(点匹配换行)、u(Unicode)标志。Test a regex live: highlights all matches, shows the match count and capture groups for each match. Flags i / m / s / u supported.
① 正则表达式① Pattern
正则元字符速查Regex cheat sheet
| . | * + ? | ^ $ | [] [^] | () (?:) | \d \w \s | \D \W \S | {n,m} | | \b \B |
|---|---|---|---|---|---|---|---|---|
| 任意字符(默认不含换行)Any char (not newline) | 重复:0+ / 1+ / 0 或 1Repeat: 0+ / 1+ / 0-or-1 | 行首 / 行尾Start / end of line | 字符集 / 取反Class / negated | 捕获组 / 非捕获组Group / non-capture | 数字 / 单词 / 空白Digit / word / space | 非数字 / 非单词 / 非空白Not digit / word / space | 量词:出现 n–m 次Quantifier n–m times | 或 / 词边界 / 非词边界Or / word boundary |
常用组合:\d{4}-\d{2}-\d{2} 日期;[a-zA-Z0-9_]+ 单词;^(?!.*evil) 负向前瞻排除。勾选 s 标志让 . 跨行。Examples: \d{4}-\d{2}-\d{2} dates; [a-zA-Z0-9_]+ words; ^(?!.*evil) negative lookahead. Flag s makes . span lines.
② 测试文本② Test text
③ 匹配结果③ Matches
④ 替换④ Replace
在下方输入替换内容,支持用 $1、$2… 引用捕获组。替换结果实时更新,可复制或下载。Enter replacement below; use $1, $2… to reference capture groups. Result updates live; copy or download it.
使用说明How to use
- 输入正则表达式Enter a regular expression
- 填写标志(i 忽略大小写、m 多行、s 跨行、u)与测试文本Set flags (i/m/s/u) and the test text
- 查看高亮匹配、分组与替换预览See highlighted matches, groups and replace preview
示例:\d+ 匹配文本中的所有数字Example: \d+ matches all numbers
全程在你的浏览器本地完成,文本不会上传服务器。Runs entirely in your browser; your text is never uploaded.
正则始终以全局模式(g)运行,因此会标出全部匹配。若表达式含捕获组 (…),在下方列出每一处匹配的分组内容。表达式无效时会提示错误,不会影响已输入文本。The pattern always runs globally (g) so every match is highlighted. Capture groups (…) are listed per match below. Invalid patterns show an error without affecting your text.