正则表达式1
$ 表示寻找指定字符串的结尾的位置,\b 表示单词的边界例如:
var reg4=/are$/g; var reg5=/are\b/g; var str="we are thinking that that cars are"; console.log(str.match(reg4)); //["are"] console.log(str.match(reg5)); //["are", "are"]
反向引用查找重复的单词:
var reg3=/([A-Za-z]+)\s+\1\b/g; var str="we are thinking that that cars are"; console.log(str.match(reg3)); //["that that"]