国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

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

圖片精選

主站蜘蛛池模板: 敦化市| 洱源县| 嫩江县| 昌江| 阿拉善左旗| 怀远县| 崇义县| 都匀市| 鹤壁市| 绵竹市| 汾西县| 祁阳县| 榆林市| 灵宝市| 黄陵县| 仙游县| 枝江市| 孝昌县| 新泰市| 连江县| 河间市| 迭部县| 宜春市| 大石桥市| 台东市| 夹江县| 闽侯县| 祁阳县| 曲松县| 如皋市| 忻城县| 洪洞县| 大同市| SHOW| 忻州市| 福清市| 琼结县| 盘山县| 黔西县| 集贤县| 榆中县|