Developer
Regex Tester & Extractor
实时测试正则表达式,高亮匹配结果,查看捕获组并生成代码片段。
Regex Workspace
匹配数: 2HIGHLIGHT RESULT
product-120 order-42 invalid
CAPTURE GROUPS
| # | 完整匹配 | 分组 |
|---|---|---|
| 1 | product-120 | g1: product | g2: 120 |
| 2 | order-42 | g1: order | g2: 42 |
Reference
Regex Cheat Sheet
| Token | Meaning |
|---|---|
| . | Any character except newline |
| \d | Digit (0-9) |
| \w | Word character |
| \s | Whitespace |
| ^ / $ | Start / end of line |
| [abc] | Any character in class |
| [^abc] | Any character not in class |
| ( ... ) | Capture group |
| (?: ... ) | Non-capturing group |
| a|b | Alternation |
| * + ? | Quantifiers |
| {n,m} | Range quantifier |
Code Snippet
const regex = new RegExp('(\\w+)-(\\d+)', 'g');
const text = 'product-120
order-42
invalid';
const matches = [...text.matchAll(regex.global ? regex : new RegExp(regex.source, regex.flags + 'g'))];
console.log(matches);Share
您可能还喜欢
- JSON 路径查找器检查 JSON,复制准确的 JSONPath 表达式,并在本地测试路径。
- URL 编码解码器在浏览器中本地编码和解码 URL 组件。
- Base64 编码解码器在浏览器中本地编码和解码 Base64 文本。
- GUID / UUID 生成器在浏览器中本地生成 UUID 并将 GUID 转为短 GUID。
- JSON 格式化即时格式化、验证和压缩JSON。一键复制。
- Cron 解析器解析包含命令的完整 crontab 行,说明计划并显示接下来的 5 次执行时间。
- HTML 预览器编写或粘贴 HTML,在沙盒 iframe 中实时预览。支持完整页面和片段。100% 本地运行。
- JWT 解码器即时解码并检查 JWT 令牌。查看 header、payload 声明和过期状态。
- Number Base ConverterInstantly convert numbers between binary, octal, decimal, and hexadecimal. Supports large numbers. 100% client-side.
- Unix 时间戳转换器将 Unix epoch 秒转换为日期时间,反之亦然。100% 客户端。