正则-连续相同的单词

var str = "Is is the cost of of gasoline going up up";
var patt1 = /b([a-z]+) 1b/ig;//   1前面有空格
document.write(str.match(patt1));
 
运行结果
Is is,of of,up up
 
正则表达式中,圆括号(),会整体匹配(相比于[]方括号的单独匹配),同时会有一个临时缓冲区
一个表达式中出现多个圆括号,就有多个缓冲区,缓冲区通过   k   来引用
1    2  分别就是第一个第二个圆括号的缓冲区
因此可以匹配重复
原文地址:https://www.cnblogs.com/lxzbky/p/11013609.html