子模式的正则表达式

subpattern regex

本文关键字:正则表达式 子模式      更新时间:2023-09-26

我需要用一个正则表达式检索字符串上的所有匹配:

var str = "lorem -req=aaa(opt:3,m:2),bbb(opt:4) ipsum ",
res = str.match(/.../); //  ???? 

使用什么来获取类似

的内容
[
  ['aaa', 'opt:3,m:2'],
  ['bbb', 'opt:4']
]

可以不使用函数吗?

你可以试试:

[=,]([^'(]*)'(([^')]*)')

解释

第1组和第2组包含您的匹配项