首页 Home/正则测试器 / Regex Tester

正则测试器 · Regex Tester

正则表达式是处理文本的强大工具,但调试时经常需要反复确认表达式是否按预期匹配。本工具提供实时的正则测试环境:输入表达式与修饰符后,测试文本中的匹配结果会立即高亮显示。

Regular expressions are powerful for text processing, but debugging them means constantly checking whether a pattern matches as expected. This tool provides a live regex testing environment: enter a pattern and flags, and matches in the test text highlight immediately.

正则测试器Regex Tester
INPUT0 chars
OUTPUT
结果会显示在这里
提示:所有处理都在你的浏览器本地完成。输入后自动更新结果

正则测试器 / Regex Tester

功能介绍(中文)

正则表达式是处理文本的强大工具,但调试时经常需要反复确认表达式是否按预期匹配。本工具提供实时的正则测试环境:输入表达式与修饰符后,测试文本中的匹配结果会立即高亮显示。

浏览器支持 d(hasIndices)标志时,工具会按捕获分组着色高亮,最多循环使用 6 种颜色,并列出每次匹配中 $1、$2 等分组的值与索引区间;不支持时降级为完整匹配高亮。

内置手机号、邮箱、身份证、IPv4、URL、日期、中文、十六进制颜色、用户名、正整数等 10 个常用模板,点击即可填入表达式和修饰符。其中 IPv4 模板严格限制每段为 0–255 并拒绝前导零。

Overview (English)

Regular expressions are powerful for text processing, but debugging them means constantly checking whether a pattern matches as expected. This tool provides a live regex testing environment: enter a pattern and flags, and matches in the test text highlight immediately.

When the browser supports the d (hasIndices) flag, matches are colored by capture group with up to six rotating colors, and each match lists its $1, $2 group values and index ranges. Otherwise it falls back to highlighting whole matches.

Ten built-in templates cover phone numbers, email, ID cards, IPv4, URLs, dates, Chinese text, hex colors, usernames and positive integers. The IPv4 template strictly restricts each octet to 0–255 and rejects leading zeros.

功能特点(中文)

  • 实时匹配,支持 g / i / m / s / u / y 修饰符
  • 捕获分组着色高亮,最多 6 色循环
  • 列出每次匹配的分组值与索引区间
  • 10 个常用正则模板,点击即填入
  • IPv4 模板严格校验 0–255 且拒绝前导零

Features (English)

  • Live matching with g / i / m / s / u / y flags
  • Capture group highlighting with up to six colors
  • Group values and index ranges for every match
  • Ten common templates, inserted with one click
  • IPv4 template strictly validates 0–255 and rejects leading zeros

常见问题 / FAQ

正则表达式中的 g、i、m 修饰符是什么意思?

g 表示全局匹配(查找所有结果而不是第一个);i 表示忽略大小写;m 表示多行模式,让 ^ 和 $ 匹配每一行的开头和结尾。此外 s 让 . 匹配换行,u 启用 Unicode 模式,y 启用粘连匹配。

What do the g, i and m regex flags mean?

g means global matching (find all results instead of the first); i means case-insensitive; m means multiline so ^ and $ match each line. In addition, s lets . match newlines, u enables Unicode mode and y enables sticky matching.

什么是捕获分组高亮?

正则里用圆括号括起来的部分叫捕获分组。分组高亮会用不同颜色显示每个分组匹配到的内容,并列出 $1、$2 等对应的值,便于确认表达式结构是否正确。

What is capture group highlighting?

Parts wrapped in parentheses in a regex are capture groups. Group highlighting colors each group's matched text differently and lists $1, $2 values so you can verify the pattern structure.

← 返回全部工具 / All tools

已复制到剪贴板