码迷,mamicode.com
首页 > 其他好文 > 详细

replace之$1、$2等

时间:2017-04-27 15:40:45      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:class   第一个   xxxx   字符串   bsp   blog   xxx   pre   res   

 

 

正则表达式为:/(\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)

 

replace之$1、$2等

标签:class   第一个   xxxx   字符串   bsp   blog   xxx   pre   res   

原文地址:http://www.cnblogs.com/wangxuehao/p/6774286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!