我要在表达式内传递变量吗?
我的霸王龙是:
/([01])010010/g
要在正则表达式中传递变量STR
而不是010010
。怎么了?
是这样的:
var str = 010010;
/([01]) + STR + /g
完整代码:
let a ="1111111010011001011001100111111111010011100111010001011110011101000100010110010101000011111000011110100101010111111010010011111";
let matches = [];
var STR = '010010';
a.replace(/([01])010010/g,(_,charbefore)=>{
matches.push(charbefore);
});
console.log(matches);