gpt4 book ai didi

java - 多次正则表达式两个字符串之间的所有内容

转载 作者:行者123 更新时间:2023-12-01 07:06:31 26 4
gpt4 key购买 nike

我有一个像

这样的字符串
[{"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。我试图获取标签和逗号之间的所有内容,但它不起作用

"(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

关于java - 多次正则表达式两个字符串之间的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22507774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com