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
Replace: Regular match according to pattern, replacing match result with replacement
<script type= "Text/javascript" > var str = "I love china!" ; var pattern =/i/g; var ret = str.replace (pattern, "I"); // I Love china! </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.
<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!"]
JavaScript Regular Expression Summary (test|match|search|replace|split|exec)