var s = 'caption:"My Test Caption" value:"My Test Value"'
var r = /caption:"(.+)"\s+value:"(.+)"/
var a = s.match(r);
obj = {caption: a[1], value: a[2]}
var myString = 'caption:"My Test Caption" value:"My Test Value"';
var myRegex = /caption:"(.*)" value:"(.*)"/g;
results = myRegex.exec(myString);
console.log(results[1])
console.log(results[2])
2条答案
按热度按时间1zmg4dgp1#
因为这个问题并没有说明标题和值的允许值,我假设标题可以有任何字母表(最少1个字母表)
w46czmvw2#
先从这里开始。
下面是另一篇关于javascript regex中匹配组的文章:How do you access the matched groups in a JavaScript regular expression?