正则表达式为:/(\d{3})(\d{2})/g
在要替换的内容中,$1代表第一个括号中匹配到的结果111,$2代表第二个括号中匹配到的结果22
ps:replace不会改变原来的字符串,只将结果返回
var str =‘11122xxxx‘; var res= str.replace(/(\d{3})(\d{2})/g,‘a$1b$2c‘); document.write(res); //a111b22cxxxx console.log(RegExp.$1) //111 console.log(RegExp.$2) //22 console.log(RegExp.$3)
时间: 2024-10-10 00:13:07