多次使用两个字符串之间的正则表达式(Regex everything between two strings multiple times)
我有一个类似的字符串
[{"id":"9","label":"P","price":"0","oldPrice":"0","products":["606","610","614","618","622","625","629"]},{"id":"8","label":"M","price":"0","oldPrice":"0","products":["607","611","615","619","626","630"]},{"id":"7","label":"G","price":"0","oldPrice":"0","products":["609","613","617","621","624","628","632"]},{"id":"36","label":"GG","price":"0","oldPrice":"0","products":["608","612","616","620","623","627","631"]},{"id":"152","label":"XGG","price":"0","oldPrice":"0","products":["3713","6577","6578","6579","6580","6581","6582"]}]我需要的是标签值:P,M,G,GG,XGG。 我试图获得标签和逗号之间的所有内容,但它不起作用
“(标签)(。*)(,)”
I have a String like
[{"id":"9","label":"P","price":"0","oldPrice":"0","products":["606","610","614","618","622","625","629"]},{"id":"8","label":"M","price":"0","oldPrice":"0","products":["607","611","615","619","626","630"]},{"id":"7","label":"G","price":"0","oldPrice":"0","products":["609","613","617","621","624","628","632"]},{"id":"36","label":"GG","price":"0","oldPrice":"0","products":["608","612","616","620","623","627","631"]},{"id":"152","label":"XGG","price":"0","oldPrice":"0","products":["3713","6577","6578","6579","6580","6581","6582"]}]What i need is the label values: P, M, G, GG, XGG. i tried to get everything between label and a comma, but its not working
"(label)(.*)(,)"
最满意答案
(?<=label\"\:)\"\w+\"这样做会
或者如果你真的想把它解析为json
做这个
var arr = []; var jso = [{"id":"9","label":"P","price":"0","oldPrice":"0","products":["606","610","614","618","622","625","629"]},{"id":"8","label":"M","price":"0","oldPrice":"0","products":["607","611","615","619","626","630"]},{"id":"7","label":"G","price":"0","oldPrice":"0","products":["609","613","617","621","624","628","632"]},{"id":"36","label":"GG","price":"0","oldPrice":"0","products":["608","612","616","620","623","627","631"]},{"id":"152","label":"XGG","price":"0","oldPrice":"0","products":["3713","6577","6578","6579","6580","6581","6582"]}]; console.log(jso.length); for(var i=0;i<jso.length;i++){ arr.push(jso[i].label); } console.log(arr);正则表达式演示: http : //regex101.com/r/kT9kE6
(?<=label\"\:)\"\w+\"this will do it
or if you really want to parse it as json
do this
var arr = []; var jso = [{"id":"9","label":"P","price":"0","oldPrice":"0","products":["606","610","614","618","622","625","629"]},{"id":"8","label":"M","price":"0","oldPrice":"0","products":["607","611","615","619","626","630"]},{"id":"7","label":"G","price":"0","oldPrice":"0","products":["609","613","617","621","624","628","632"]},{"id":"36","label":"GG","price":"0","oldPrice":"0","products":["608","612","616","620","623","627","631"]},{"id":"152","label":"XGG","price":"0","oldPrice":"0","products":["3713","6577","6578","6579","6580","6581","6582"]}]; console.log(jso.length); for(var i=0;i<jso.length;i++){ arr.push(jso[i].label); } console.log(arr);regex demo : http://regex101.com/r/kT9kE6
更多推荐
发布评论