RegExp.$1

RegExp.$n是非标准的,尽量不要在生产环境中使用。
【RegExp.$n】(n为1-9之间的数值)指的是与正则表达式匹配的第n个 子匹配(以括号为标志)字符串。
【RegExp.$_】与正则表达式匹配的完整字符串。

RegExp.$n示例

var reg=/(\w+)-(\w+)-(\w+)-(\w+)/
reg.exec('My-name-is-Lucy!')
console.log(RegExp.$_)  //"My-name-is-Lucy!"
console.log(RegExp.$1)  //"My"
console.log(RegExp.$2)  //"name"
console.log(RegExp.$3)  //"is"
console.log(RegExp.$4)  //"Lucy!"

猜你喜欢

转载自blog.csdn.net/yihanzhi/article/details/79870604
今日推荐