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

正则表达式的$

时间:2017-09-06 16:44:55      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:ons   使用   logs   strong   com   str   编号   正则   htm   

正则表达式中的$代表的是捕获组,关于捕获组,可参考: http://www.cnblogs.com/yanze/p/6358557.html

$1、$2...

代表第一个捕获组,第二个捕获组...可使用多个,对号入座,编号错误忽略

var str= ‘00习大大11温家宝22‘
str= str.replace(/(习大大)|(温家宝)/g, "<<$1$2>>")
console.log(str) //00<<习大大>>11<<温家宝>>22

$& 

代表所有捕获组

var str= ‘00习大大11温家宝22‘
str= str.replace(/(习大大)|(温家宝)/g, "<<$&>>")
console.log(str) //00<<习大大>>11<<温家宝>>22

$`

代表捕获组左侧文本

var str= ‘00习大大11温家宝22‘
str= str.replace(/(习大大)|(温家宝)/g, "<<$&>>")
console.log(str)  //00<<00>>11<<00习大大11>>22

&‘

代表捕获组右侧文本

var str= ‘00习大大11温家宝22‘
str= str.replace(/(习大大)|(温家宝)/g, "<<$‘>>")
console.log(str) //00<<11温家宝22>>11<<22>>22

正则表达式的$

标签:ons   使用   logs   strong   com   str   编号   正则   htm   

原文地址:http://www.cnblogs.com/yanze/p/7485570.html

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