开发者

正则表达式测试与提取

实时测试正则表达式,高亮匹配结果,查看捕获组并生成代码片段。

正则工作区
匹配数: 2
高亮结果
product-120
order-42
invalid
捕获组
#完整匹配分组
1product-120g1: product | g2: 120
2order-42g1: order | g2: 42
参考

正则速查表

符号含义
.Any character except newline
\dDigit (0-9)
\wWord character
\sWhitespace
^ / $Start / end of line
[abc]Any character in class
[^abc]Any character not in class
( ... )Capture group
(?: ... )Non-capturing group
a|bAlternation
* + ?Quantifiers
{n,m}Range quantifier

代码片段

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

您可能还喜欢