国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript使用RegExp進(jìn)行正則匹配的方法

2019-11-20 12:03:49
字體:
供稿:網(wǎng)友

本文實例講述了JavaScript使用RegExp進(jìn)行正則匹配的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

<script type="text/javascript">  var matchedTimes = 0;  //Match one d followed by one or more b's followed by one d  //Remember matched b's and the following d  //Ignore case  myRe  = new RegExp("d(b+)(d)", "ig");  // 等價于 myReg = /d(b+)(d)/ig;  myArray = myRe.exec("ecDBDsdbbdz"); // ecdbBdbsdbbdz  console.log("Regular Expression String: " + myRe.source);  console.log("Is global? " + myRe.global);  console.log("Ignore case? " + myRe.ignoreCase);  console.log("Is mulitiline? " + myRe.multiline);  console.log("------------------------------------------------");  logInfo(myArray, myRe);  myArray = myRe.exec("ecDBDsdbbdz");  logInfo(myArray, myRe);  function logInfo(myArray, myRe) {    matchedTimes++;    console.log("This is " + matchedTimes + " times match");    console.log("Original String: " + myArray.input);    console.log("Match Result Array: [" + myArray + "]");    console.log("The 0-based index of the match in the string: " + myArray.index);    console.log("The last matched characters: " + myArray[0]);    console.log("The parenthesized substring matches [1]: " + myArray[1]);    console.log("The parenthesized substring matches [2]: " + myArray[2]);    console.log("The index at which to start the next match: " + myRe.lastIndex);    console.log("-----------------------------------------------");  }  myRe2 = /^/w+(/d*)$/ig  console.log("myRe2: " + myRe2.source);  //console.log("myRe2 matches abc1? " + myRe2.test("abc1"));  // 加上這行跑跑看結(jié)果,因為是global匹配,所以lastIndex會改變,  //所以后面的myRe2.test("abc")當(dāng)然就是false  console.log("myRe2 matches abc? " + myRe2.test("abc"));</script>

希望本文所述對大家的javascript程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 长葛市| 南充市| 正阳县| 锡林浩特市| 佛教| 桂林市| 萍乡市| 鹤山市| 台前县| 额尔古纳市| 鄂托克前旗| 上思县| 本溪| 慈利县| 察隅县| 越西县| 光山县| 舞钢市| 永春县| 庐江县| 德令哈市| 兴业县| 海兴县| 长寿区| 米泉市| 南丰县| 瓮安县| 库尔勒市| 桓台县| 桂东县| 潢川县| 九寨沟县| 收藏| 新巴尔虎左旗| 绵竹市| 华安县| 贵港市| 台北市| 连江县| 年辖:市辖区| 广南县|