Test : Tests whether a string contains a matching result, contains a return of true, and does not contain a return of false.
<script type= "Text/javascript" > var str = "bbs.byr.cn"; var reg =/b/; var ret = reg.test (str); // true </script>
match: Regular match based on pattern, if matched to, returns match result, such as no match to return null
<script type= "Text/javascript" > var str = "This isn ' t me"; var reg =/is/ig; var ret = str.match (reg); // is, is // [' Is ', ' is '] </script>
Search : a regular match based on pattern, and returns the number of indexes if it matches a result; 1
<script type= "Text/javascript" > var str = "This isn ' t me"; var reg =/is/; var ret = str.search (reg); alert (ret); // 2 </script>
Replace: Regular match according to pattern, replace the match result with replacement, the second parameter can be changed to function.
<script type= "Text/javascript" > var str = "I love china!" var pattern =/i/G; var ret = str.replace (pattern, "I" ); alert (ret); // i Love china! </script>
<script type= "Text/javascript" > var argv = ["1", "2"]; var str = "%s,%s"; var i = 0; function () { return argv[i++]; }); </script>
Split: Regular segmentation According to pattern, returns a segmented array
<script type= "Text/javascript" > var str = ' http://www.baidu.com/'; var reg =/\w/; var ret = str.split (reg); // ["http", "", "", "www", "Baidu", "com", "" " ) </script>
exec: string is processed in regular order, and the matching result is returned. Array[0] is the original string, Array[i] is the position of the match within the entire searched string. you can use the while (arr = re.exec (str)) = null) to find all .
<script type= "Text/javascript" > var str = "I love china!" ; var reg =/i\b/g; var ret = reg.exec (str); // I // ["I", index:9, Input: "I love china!"] </script>
Javascript-Common regular function (for forgetting to see)