正则表达式测试Regex Tester
在线正则表达式测试工具,实时匹配高亮Online regex tester with real-time matching and highlighting.
关于 正则表达式测试About Regex Tester
正则表达式是文本匹配与提取的利器,但编写过程常常像“黑盒”:不运行一下根本不知道匹配了什么。本工具在你输入的同时实时高亮匹配结果,并列出全部匹配项与捕获分组,帮助开发者快速迭代、验证正则表达式。Regular expressions are powerful for matching and extracting text, but authoring them often feels like a black box — you never know what matches until you run it. This tool highlights matches in real time as you type and lists every match and capture group, so you can iterate and verify patterns quickly.
使用方法How to Use
- 在表达式输入框中填写正则表达式,按需选择全局、忽略大小写等标志。Type your regex into the pattern box and pick flags such as global or case-insensitive as needed.
- 将待匹配的测试文本粘贴到文本区域。Paste the test text into the text area.
- 页面会实时高亮所有匹配内容,并在下方展示分组捕获详情。The page highlights all matches in real time and shows capture-group details below.
- 根据匹配结果调整表达式,直到符合预期后复制到代码中使用。Adjust the pattern until it behaves as expected, then copy it into your code.
常见问题FAQ
常用的正则标志有哪些?What are the common regex flags?
g 表示全局匹配(找出所有匹配而非第一个),i 表示忽略大小写,m 表示多行模式(让 ^ 和 $ 匹配每一行的行首行尾)。组合使用可以显著改变匹配行为。g means global (find all matches, not just the first), i ignores case, and m enables multiline mode (^ and $ match each line). Combining them changes matching behaviour significantly.
贪婪匹配和懒惰匹配有什么区别?What is the difference between greedy and lazy matching?
量词 *、+ 默认是贪婪的,会尽可能多地匹配字符;在其后加 ? 变为懒惰模式,尽可能少地匹配。提取两个符号之间的内容时,懒惰匹配通常更准确。Quantifiers like * and + are greedy by default and match as much as possible; appending ? makes them lazy, matching as little as possible. Lazy matching is usually more accurate when extracting content between two delimiters.
为什么代码里能用的正则在这里不生效?Why does a regex that works in my code fail here?
请检查是否在代码字符串中做了双重转义(如 \d 写成 \\d)。本工具直接接收正则本体,不需要字符串层面的转义。Check for double escaping inside code strings (e.g. \d written as \\d). This tool takes the raw regex body, so no string-level escaping is needed.
支持哪些正则引擎特性?Which regex engine features are supported?
基于 JavaScript 正则引擎,支持前瞻/后瞻、命名捕获组、Unicode 属性转义等 ES2018+ 特性;PCRE 的递归等引擎私有扩展不支持。Built on the JavaScript engine with lookahead/lookbehind, named capture groups and Unicode property escapes (ES2018+); engine-specific extensions like PCRE recursion are not supported.
可以测试中文和 Emoji 吗?Can I test Chinese and Emoji?
可以。文本按 UTF-8 处理,配合 u 标志可正确匹配中文、Emoji 与组合字符;匹配中文建议使用 [\u4e00-\u9fa5] 或 Unicode 属性 \p{Script=Han}。Yes. Text is handled as UTF-8; with the u flag, Chinese, Emoji and combining sequences match correctly. For Chinese, use [\u4e00-\u9fa5] or the Unicode property \p{Script=Han}.
相关阅读Related Reading
相关工具Related Tools
JSON 格式化JSON Formatter
在线JSON格式化、校验、压缩、美化工具Online JSON formatter, validator, compressor and beautifier.
随机密码生成器Password Generator
生成高强度随机密码,支持自定义长度和字符集Generate strong random passwords with customizable length and charset.
UUID 生成器UUID Generator
在线生成UUID/GUID,支持批量生成Generate UUID/GUID online, supports batch generation.
JSON 转换工具JSON Converter
JSON与XML/CSV/YAML格式互相转换Convert JSON to/from XML, CSV and YAML formats.