Toolypet
开发工具/正则表达式测试器

正则表达式测试器

实时匹配测试和调试正则表达式

模式

测试字符串

匹配结果 (0 个匹配)

未找到匹配

Regular Expressions Guide

Learn how to test and debug regular expressions

What are Regular Expressions?

Regular expressions (regex) are patterns used to match character combinations in strings. They are powerful tools for searching, validating, and manipulating text data in programming.

How to Use This Tool

  1. Enter your regex pattern in the pattern field
  2. Select the flags you need (global, case-insensitive, multiline)
  3. Enter or paste your test text in the test string field
  4. View highlighted matches and match details in real-time

Pro Tips

  • Use the global flag (g) to find all matches, not just the first one
  • The multiline flag (m) makes ^ and $ match line starts/ends
  • Escape special characters like . * + ? with a backslash (\)

Browser Support

Regular expressions are natively supported in all modern browsers through JavaScript's RegExp object. This tool uses standard JavaScript regex syntax.

常见问题

常用的正则表达式元字符有哪些?

. 匹配任意字符;* 匹配0次或多次;+ 匹配1次或多次;? 匹配0次或1次;^ 行首;$ 行尾;\d 数字;\w 字母数字下划线;\s 空白字符;[abc] 字符类;(abc) 分组。

g、i、m标志分别是什么意思?

g (global) 全局搜索,找到所有匹配而非仅第一个。i (ignore case) 忽略大小写。m (multiline) 多行模式,使^和$匹配每行的开头和结尾而非整个字符串的开头结尾。

贪婪匹配和惰性匹配有什么区别?

贪婪匹配(默认)尽可能多地匹配字符,如.*会匹配到最后一个可能的位置。惰性匹配(加?)尽可能少地匹配,如.*?会匹配最短的字符串。例如对于'<a>text</a>',<.*>匹配整个字符串,<.*?>只匹配'<a>'。

如何匹配特殊字符本身?

使用反斜杠\转义特殊字符。例如匹配点号用\.,匹配问号用\?,匹配括号用\(和\)。需要转义的字符包括:. * + ? ^ $ { } [ ] ( ) | \

常用的正则表达式模式有哪些?

电子邮件:[\w.-]+@[\w.-]+\.\w+;电话号码:\d{3}-\d{3,4}-\d{4};URL:https?://[\w.-]+(/[\w.-]*)*;日期:\d{4}-\d{2}-\d{2};中文字符:[\u4e00-\u9fa5]+。实际使用时需根据具体需求调整。