Learn JavaScript regular Good Article one: http://www.cainiao8.com/web/js_note/js_regular_expression.html
Test : Tests whether a string contains a matching result, contains return true, and does not contain return false.
<script type= "Text/javascript" >
var str = "bbs.byr.cn";
var reg =/b/;
var ret = reg.test (str);
alert (ret); True
Match : A regular match based on pattern and, if matched to, returns a matching result, such as a match that does not return a null
<script type= "Text/javascript" >
var str = "This isn ' t me";
var reg =/is/ig;
var ret = Str.match (reg);
alert (ret); Is, is
console.log (ret);//[' is ', ' is ']
Search : A regular match based on pattern, or the number of indexes if it matches to a result, or return 1
<script type= "Text/javascript" >
var str = "This isn ' t me";
var reg =/is/;
var ret = Str.search (reg);
alert (ret);//2
Replace: a regular match based on pattern, replacing the result with a replacement
<script type= "Text/javascript" >
var str = "I love china!";
var pattern =/i/g;
var ret = str.replace (pattern, "I");
alert (ret); I Love china!
Split : Regular segmentation based on pattern, return of a segmented array
<script type= "Text/javascript" >
var str = ' http://www.baidu.com/';
var reg =/\w/;
var ret = Str.split (reg);
Console.log (ret); ["http", "" "," "," www "," Baidu "," com "," "]
exec : Regular processing of string and return of matching results. Array[0] is the original string, Array[i] to match the position in the entire searched string.
<script type= "Text/javascript" >
var str = "I love china!";
var reg =/i\b/g;
var ret = reg.exec (str);
alert (ret); I
Console.log (ret);//["I", index:9, Input: "I love china!"]
The above is a small series to introduce the JavaScript regular expression summary (test|match|search|replace|split|exec), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!