// DEV / REGEX
正则测试Regex Tester
实时匹配高亮、捕获分组、替换预览,内置常用模式可直接套用。Live match highlighting, capture groups and replace preview, with a built-in pattern library.
语法速查,点击插入到光标处Syntax cheatsheet, click to insert at caret
未勾选 g 时只替换第一处;替换结果实时更新。Without the g flag only the first match is replaced.
const re = //g; const text = ""; console.log(text.match(re));
数字 / Numbers
^-?\d+$允许正负号与前导零Allows sign and leading zeros
^-?\d+(?:\.\d+)?$不支持指数记法No exponent notation
^\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$只校验格式,不做数值运算Format only, no arithmetic
字符 / Characters
[\u4e00-\u9fa5]基本汉字区,不含扩展区Basic CJK block only
^\w+$等价于 [A-Za-z0-9_]Same as [A-Za-z0-9_]
^\s*$配合多行模式逐行判断Use with multiline mode
网络 / Network
^[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}$常见格式粗筛,不验证可投递Rough format check, not deliverability
^https?://[^\s]+$只判断外形,完整解析用 URL 工具Shape only, use the URL tool to parse
^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$每段 0-255,拒绝前导零Each octet 0-255, no leading zeros
^1[3-9]\d{9}$大陆 11 位外形,不含最新号段校验Mainland 11-digit shape only
日期与时间 / Date & time
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$YYYY-MM-DD,不判断大小月YYYY-MM-DD, month length unchecked
^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$HH:mm 或 HH:mm:ssHH:mm or HH:mm:ss
匹配上限 200 条、时间预算 300ms。JavaScript 的单次匹配无法中断,极端表达式仍可能短暂卡顿。Up to 200 matches and a 300ms budget. A single JavaScript match cannot be interrupted, so pathological patterns may still stall briefly.
常见问题FAQ
正则测试支持哪些语言的正则语法?Which regex flavors are supported?
匹配本身使用 JavaScript 的 RegExp 引擎,同时可以生成 JavaScript、Python、Java、Go、PHP 五种语言的等效代码,方便复制到项目里。Matching uses the JavaScript RegExp engine, and the tool also generates equivalent code for JavaScript, Python, Java, Go and PHP so you can paste it into a project.
能看到捕获分组的内容吗?Can I inspect capture groups?
能。匹配列表会显示每处匹配的起止位置与分组内容,替换预览实时更新,还可以导出为 JSON。Yes. Each match lists its start and end offsets and the captured groups, the replacement preview updates live, and results can be exported as JSON.
同类工具Related tools
- JSON 格式化JSON Formatter
- JSON 校验JSON Validator
- JSON 对比JSON Diff
- YAML / JSON 互转YAML ↔ JSON
- Base64 编解码Base64 Encode / Decode
- Unicode 编解码Unicode Encoder
- URL 编解码URL Encode / Decode
- URL 解析URL Parser
- 哈希生成Hash Generator
- 密码强度检测Password Checker
- 随机密码Password Generator
- 颜色转换Color Converter
- User Agent 解析User Agent Parser
- UUID 生成UUID Generator
- 时间戳转换Timestamp Converter