Regular expressions use other methods
- The regular expression: g represents the global pattern matching
- Regular expressions: i represents the Ignore case
var STR = "China Mobile: 10086, China Unicom: 10010, China Telecom: 10000" ; // put all numbers displayed inside out all var Array str.match = (/ \. 5} {D / G); console.log(array);
// extracted here date var STR = "2017-11-12" ; var Array str.match = (/ (\ {D}. 4) [-] (\ D {2}) [-] (\ D {2 }) / G); // the console.log (Array); // regular expression object. 3 $. the console.log (the RegExp $. 3).;
var email = "[email protected]"; email.match ( / ([0-9a-zA-Z _.-] +) [@] ([0-9a-zA-Z _-] +) (([.] [a-zA-Z] +) { 1,2}) / ); console.log ($ RegExp. 1); // username console.log (RegExp $ 2.); // 126 console.log (RegExp $ 3.); // domain name
var str = "Little Su Shuaio good, really handsome, handsome, that is so cool" ; STR = str.replace (/ handsome / g, "smart" ); console.log(str); var str = "Oh buy the Karma, too happy" ; str = str.trim (); console.log("===" + str + "==="); var str = "Oh buy the Karma, too happy" ; str = str.replace(/\s+/g, ""); console.log("===" + str + "===");
// All are replaced h S var REG = new new the RegExp (/ [h] / GI); var STR = "HhpphH"; // SSppSS STR = str.replace (REG, "S" ); console.log(str);
var STR = "China Mobile: 10086, China Unicom: 10010, China Telecom: 10000" ; var REG = / \ {D}. 5 / G; // regular expression matching string var Array = reg.exec (STR ); the while ! (Array = null ) { // output content that matches the console.log (Array [0 ]); array = reg.exec(str); }