是这样的,
","question_id":1553,"flag":1,","question_id":1554,"flag":0,","question_id":1555,"flag":1.。。
我想替换,把question_id后面都跟的数字,比如1553,这一行,都替换成ccc,"question_id":1554,"就是前面加个ccc
for (var i=0;i<2000;i++)
{var ccc='","question_id":'+i+',"flag":1,';
var ddd='111","question_id":'+i+',"flag":1,';
ddd.replace(ccc,ddd);
}
我现在用循环写的,我意思能不能用一行代码,不用循环用正则写,比如
ddd.replace(","question_id":'/d,","ccc,question_id":'/d);
第1个回答 2018-12-14
表达式:aaa:\w+
第2个回答 2018-12-14
己亥岁感事(曹松)
第3个回答 2018-12-14
如果只匹配aaa后的数字:
// demovar str = "aaa:a111a";
var reg = /aaa:(?:[^\d]+)?([\d]+)(?:[^\d]+)?/;
var result = "";
if (reg.test(str)) {
result = RegExp.$1;
}
如果匹配aaa后的所有内容:
var str = "aaa:a111a";
var reg = /aaa:([\s\S]+)/;
var result = "";
if (reg.test(str)) {
result = RegExp.$1;
}追问
aaa:1,ccc,比如这样
我想要一个变量,var bbb='aaa'+(正则表达式)应该怎么写就是无论aaa后面数字是多少,都能匹配给bbb