JS_正则_match

1、

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 
 3 <html>
 4 
 5 <style type="text/css">
 6 </style>
 7 
 8 <script type="text/javascript" >
 9 
10     window.onload = function()
11     {
12         var str = "asdLff Ll ";
13         var rtn = str.match(/[L]/);
14         console.log(rtn);
15         console.log(rtn.length);
16         for (var i in rtn)
17         {
18             console.log(i +" ==> "+rtn[i]);
19         }
20 
21         console.log("***");
22         console.log(rtn[0]);
23         console.log(rtn["index"]);
24         console.log(rtn["input"]);
25 
26         console.log("***");
27         var rtn01 = str.match(/[A]/);
28         console.log(rtn01);
29 
30         console.log("***");
31         str = "asldLff Ll ";
32         var rtn02 = str.match(/[Ll]/);
33         console.log(rtn02);
34     };
35 
36 </script>
37 
38 </html>

 

 

 

chrome (版本 49.0.2623.87 m) 控制台输出:

a.html:14    ["L", index: 3, input: "asdLff Ll "]
a.html:15    1
a.html:18    0 ==> L
a.html:18    index ==> 3
a.html:18    input ==> asdLff Ll 
a.html:21    ***
a.html:22    L
a.html:23    3
a.html:24    asdLff Ll 
a.html:26    ***
a.html:28    null
a.html:30    ***
a.html:33    ["l", index: 2, input: "asldLff Ll "]

 

 

2、

 

posted @ 2016-03-16 14:35  Html5Skill  阅读(314)  评论(0编辑  收藏  举报