1. 程式人生 > >正則表達式1

正則表達式1

con mat .cn script 正則表達式 ons ole ges rip

技術分享

$ 表示尋找指定字符串的結尾的位置,\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"]

 

正則表達式1