Allio Tools Pro — No ads · Bulk processing · Save historyUpgrade $2.99/mo →
🚀Allio Tools Pro
  • No ads
  • Bulk tools
  • History
$2.99/mo

在线免费正则表达式测试器

Thanks for rating!

使用实时高亮测试和调试正则表达式。

🚀Allio Tools Pro
  • Zero ads everywhere
  • Bulk processing
  • Save history
Upgrade — $2.99/moNo signup required
Allio Tools Pro — No ads · Bulk processing · Save historyUpgrade $2.99/mo →

Who uses the 正则表达式测试器?

  • 后端开发者在部署前构建和测试输入验证模式。
  • 数据工程师编写用于日志解析、数据提取和字段验证的正则表达式。
  • 学生通过对测试字符串的即时可视化反馈学习正则表达式。

How the 正则表达式测试器 works

1

在 Regex 字段中输入正则表达式模式(不含斜杠)。

2

设置标志:g(全局)、i(忽略大小写)、m(多行)、s(dotall)。

3

在下方文本区域输入测试字符串——所有匹配项会立即高亮显示。

4

查看匹配表格,显示每个匹配项及其捕获组。

Tips & tricks

  • 保持勾选 g 标志,以查看所有匹配项,而不仅仅是第一个。
  • 使用捕获组——在模式中加括号——来提取日期、邮箱等结构化数据。
  • 尽早测试边界情况,比如空字符串和特殊字符——正则表达式在边界处的行为常常出人意料。
  • m 标志只改变 ^ 和 $ 的行为——它不会让 . 匹配换行符,那是 s 标志的作用。

Frequently Asked Questions

如何用正则表达式匹配邮箱地址?

一个简单的邮箱正则表达式:[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}。将它粘贴到 regex 字段并用邮箱地址测试。没有单一正则表达式能完美验证符合 RFC 5322 的所有邮箱格式。

正则标志 g、i、m、s 分别代表什么?

g = 全局(查找所有匹配项,而非只查找第一个)。i = 忽略大小写。m = 多行(^ 和 $ 匹配每行的开头/结尾,而非整个字符串)。s = dotAll(. 也能匹配换行符)。

如何使用捕获组?

用括号包裹模式的一部分即可创建组:(\d{4})-(\d{2})-(\d{2}) 可从日期中捕获年、月、日。捕获组会显示在高亮文本下方的匹配表格中。

贪婪量词和惰性量词有什么区别?

“贪婪”量词(*、+、{n,})会尽可能多地匹配。“惰性”量词(*?、+?、{n,}?)会尽可能少地匹配。对于 HTML,<.*>(贪婪)会从第一个 < 匹配到最后一个 >;<.*?>(惰性)会单独匹配每个标签。

可以测试 Python 风格的正则表达式(re 模块)吗?

本工具使用 JavaScript 正则语法,与 Python 的 re 模块相似但不完全相同。主要区别:Python 用 (?P<name>...) 表示命名组,而 JavaScript 用 (?<name>...);Python 有 \A 和 \Z,JavaScript 用 ^ 和 $。

Is my data safe when using the 正则表达式测试器?

Completely safe. The 正则表达式测试器 processes everything locally in your browser. No input data, results, or usage information is ever transmitted to or stored on any server.

Can I use the 正则表达式测试器 output in commercial projects?

Yes. The 正则表达式测试器 is a utility tool and its output carries no licensing restrictions. You are free to use results in any project, commercial or personal.

Does the 正则表达式测试器 follow official standards?

Yes. The 正则表达式测试器 is built to comply with the relevant industry standard or specification for this utility type. If you encounter an unexpected result, verify your input against the specification — edge cases outside the standard may produce undefined behaviour.

💼 Reach 100K+ developers & creators — Advertise on Allio ToolsLearn More →