// 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
0 处匹配matches
高亮预览Highlighted preview
在上方输入测试文本Type test text above

未勾选 g 时只替换第一处;替换结果实时更新。Without the g flag only the first match is replaced.

参考代码Generated code
const re = //g;
const text = "";
console.log(text.match(re));
常用模式Pattern library

数字 / Numbers

整数Integer
^-?\d+$

允许正负号与前导零Allows sign and leading zeros

小数Decimal
^-?\d+(?:\.\d+)?$

不支持指数记法No exponent notation

千分位金额Amount with commas
^\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$

只校验格式,不做数值运算Format only, no arithmetic

字符 / Characters

中文字符Chinese characters
[\u4e00-\u9fa5]

基本汉字区,不含扩展区Basic CJK block only

字母数字下划线Word characters
^\w+$

等价于 [A-Za-z0-9_]Same as [A-Za-z0-9_]

空白行Blank line
^\s*$

配合多行模式逐行判断Use with multiline mode

网络 / Network

邮箱Email
^[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}$

常见格式粗筛,不验证可投递Rough format check, not deliverability

URLURL
^https?://[^\s]+$

只判断外形,完整解析用 URL 工具Shape only, use the URL tool to parse

IPv4IPv4
^(?:(?: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

手机号Mobile number
^1[3-9]\d{9}$

大陆 11 位外形,不含最新号段校验Mainland 11-digit shape only

日期与时间 / Date & time

日期Date
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$

YYYY-MM-DD,不判断大小月YYYY-MM-DD, month length unchecked

时间Time
^(?:[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

所有计算都在你的浏览器本地完成,输入内容不会上传到任何服务器。Everything runs locally in your browser. Nothing you type is ever uploaded to a server.