1. 程式人生 > >js正則exec match測試驗證

js正則exec match測試驗證

<!DOCTYPE html>
<html>
 <head lang="en"> 
  <meta charset="utf-8" /> 
  <title></title> 
  
  <style> 
  </style>
  <script>
    var str= "cat,hat" ;
var p=/at/; //沒有g屬性
var v1 = p.exec(str)
var v2 = str.match(p)

var str= "cat,hat" ;
var p=/at/g; //注意g屬性
var v3 = p.exec(str)
var v4 = str.match(p)
 
var str= "cat2,hat8" ;
var p=/c(at)\d/;
var v5 = p.exec(str)
var v6 = str.match(p)

var someText= "web2.0 .net2.0" ;
var pattern=/(\w+)(\d)\.(\d)/g;
var outCome_exec=pattern.exec(someText);
var outCome_matc=someText.match(pattern);

var someText1= "web2.0 .net2.0" ;
var pattern1=/(\w+)(\d)\.(\d)/;
var outCome_exec1=pattern1.exec(someText1);
var outCome_matc1=someText1.match(pattern1);

var str = "SerialNum=\"0023210123456789123\" GenTime=\"2018-07-27 09:43:39\" STIME=1532655819 ETIME=1532655819 IN=eth3 OUT=eth2 SMAC=d4:ae:52:bd:a5:d3 DMAC=50:7b:9d:e9:d6:8d SIP=192.168.101.92 DIP=192.168.101.145 SPORT=36986 DPORT=80 Proto=http TransProto=tcp RX=720 TX=596 method=GET url=/aaa.html host=192.168.101.145 retcode=404";
        

var p=/(\S+)=(".*?"|\S+)/g; //注意g屬性
var t1 = p.exec(str)
var t2 = str.match(p)

console.log(t1+":"+t2)

var p1=/(\S+)=(".*?"|\S+)/; //注意g屬性
var t3 = p.exec(str)
var t4 = str.match(p1)

debugger
  </script>
 </head>
 <body> 
<div style="position: relative">
     <span class="arrow arrow-down"></span>
     <span class="arrow arrow-up"></span>
     <span class="arrow arrow-left"></span>
     <span class="arrow arrow-right"></span>
 </div>    
 </body>
</html>