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

首頁 > 語言 > JavaScript > 正文

JavaScript使用RegExp進行正則匹配的方法

2024-05-06 16:23:03
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了JavaScript使用RegExp進行正則匹配的方法,實例分析了RegExp對象在進行正則匹配時的相關使用技巧,需要的朋友可以參考下

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

 

 
  1. <script type="text/javascript"
  2. var matchedTimes = 0; 
  3. //Match one d followed by one or more b's followed by one d 
  4. //Remember matched b's and the following d 
  5. //Ignore case 
  6. myRe = new RegExp("d(b+)(d)""ig"); 
  7. // 等價于 myReg = /d(b+)(d)/ig; 
  8. myArray = myRe.exec("ecDBDsdbbdz"); // ecdbBdbsdbbdz 
  9. console.log("Regular Expression String: " + myRe.source); 
  10. console.log("Is global? " + myRe.global); 
  11. console.log("Ignore case? " + myRe.ignoreCase); 
  12. console.log("Is mulitiline? " + myRe.multiline); 
  13. console.log("------------------------------------------------"); 
  14. logInfo(myArray, myRe); 
  15. myArray = myRe.exec("ecDBDsdbbdz"); 
  16. logInfo(myArray, myRe); 
  17. function logInfo(myArray, myRe) { 
  18. matchedTimes++; 
  19. console.log("This is " + matchedTimes + " times match"); 
  20. console.log("Original String: " + myArray.input); 
  21. console.log("Match Result Array: [" + myArray + "]"); 
  22. console.log("The 0-based index of the match in the string: " + myArray.index); 
  23. console.log("The last matched characters: " + myArray[0]); 
  24. console.log("The parenthesized substring matches [1]: " + myArray[1]); 
  25. console.log("The parenthesized substring matches [2]: " + myArray[2]); 
  26. console.log("The index at which to start the next match: " + myRe.lastIndex); 
  27. console.log("-----------------------------------------------"); 
  28. myRe2 = /^/w+(/d*)$/ig 
  29. console.log("myRe2: " + myRe2.source); 
  30. //console.log("myRe2 matches abc1? " + myRe2.test("abc1")); 
  31. // 加上這行跑跑看結果,因為是global匹配,所以lastIndex會改變, 
  32. //所以后面的myRe2.test("abc")當然就是false 
  33. console.log("myRe2 matches abc? " + myRe2.test("abc")); 
  34. </script> 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 深水埗区| 惠州市| 临泽县| 武穴市| 马公市| 牟定县| 拉孜县| 河西区| 凤庆县| 阆中市| 德安县| 米脂县| 寿光市| 中宁县| 乐东| 沧州市| 合川市| 甘南县| 兴业县| 北碚区| 应城市| 潍坊市| 民和| 彭泽县| 宜兰市| 平昌县| 普宁市| 石家庄市| 关岭| 柘荣县| 兴安县| 建昌县| 嘉鱼县| 恩施市| 栖霞市| 分宜县| 同德县| 文昌市| 进贤县| 聂荣县| 太湖县|