";1627207:945375942;":{"price":"78.00"},
";1627207:771237690;":{"price":"88.00"},
";1627207:1349519332;":{"price":"58.00"},
";1627207:1554775267;":{"price":"68.00"},
/1627207:945375942;":{"price":"(\d+.\d+)"/ //这样匹配结果 78
1627207:XXXXXXXX 这种值是变量 每次循环获取到一个 分别来取得价格 该如何代写正则表达式啊
1
azh7138m 2018-06-04 00:26:08 +08:00 via Android
没看懂啥意思
给个 test input 和期望的输出看下? |
2
xqin 2018-06-04 00:31:36 +08:00
let a = `
";1627207:945375942;":{"price":"78.00"}, ";1627207:771237690;":{"price":"88.00"}, ";1627207:1349519332;":{"price":"58.00"}, ";1627207:1554775267;":{"price":"68.00"}, ` let mm = {} a.replace(/;(\d+):(\d+);":\{"price":"(.+?)"\}/g, function (all, a, b, price) { if (typeof mm[a] === 'undefined') { mm[a] = {} } mm[a][b] = price; }) console.log(JSON.stringify(mm, 0, 2)) ``` { "1627207": { "771237690": "88.00", "945375942": "78.00", "1349519332": "58.00", "1554775267": "68.00" } } ``` 得到 mm 之后, 想怎么取就怎么取.. |
3
mringg 2018-06-04 00:41:09 +08:00 via iPhone
前边也用正则匹配下就好了,提取值时候注意下分组就好了
|
4
azh7138m 2018-06-04 00:48:32 +08:00
|
5
xqin 2018-06-04 00:56:52 +08:00
|
6
gengfire 2018-06-04 08:36:36 +08:00 via iPhone
reg = new RegExp(string + var);
|
7
F1024 OP |
10
azh7138m 2018-06-04 09:38:29 +08:00 via Android
当成 JSON 直接用啊,为啥搞这么麻烦
|
11
laqow 2018-06-04 12:51:08 +08:00 via Android
第一次替换:
, →回车 第二次查找: 945375942.*?(\d+.\d+) |