//Syntax 1var zz= new RegExp (' AAA ', ' IgM '); Initializes a RegExp object $ (' #scn '). Text (zz.test (' aaaadesffd '))//tests whether the initialization object contains strings in the target string. Yes returns True No returns false//igm for 3 independently available Combined parameter//i Ignore case g full-text find m multi-line lookup
//Syntax 2The Var zz2=/^a$/i//equivalent RegExp () method IgM can be combined individually/^ to denote the end of the $ expression that is required at the beginning of the target string (' #scn '). Text (zz2.t EST (' adcesffd ')) var zz3=/\s///test contains spaces () contains carriage return tab wrap var zz4=/[a-za-z_][0-9]///test contains lowercase A to Z uppercase range A to Z underscore, number 0-9, one The square brackets represent a var zz5 =/\w\d+///W for all characters and representatives say that there is a number + sign that must appear at least once in the target string, and can also be replaced with an * number, indicating that there are 0 or more rows
//-----------------------exec method---------------------------------------//var ass=/^ ([a-za-z]*) \s+ (\d)/.exec ("LF")//exec () method exec is to get an array of matching results, a few parentheses are grouped to match a few paragraphs (i.e. several elements)///upstream code match character segment , the matching number of a//result array is: "LF", ' lf ', ' ', ' bss=/^ ' var ([a-za-z]) * (\s+) (\d+)/.exec ("LF 18") The upstream code matches all of the paragraph, matches the space segment, matches the number of A//result array: "LF", "LF", ","//console. Log (' #scn '). Text (ass[1])//value LF})
//----------------------Replace method---------------------------------------//var dss=/&/var stra= ' &&&8888&&& ' Console.log (Stra.replace (/&/, ' e '))//E&&A mp;8888&&& Console.log (Stra.replace (/&/g, ' e '))//Eee8888eee Console.log (Stra.replace (/&+/g, ' E '))//e8888e
JS Regular expression 1; (basic syntax, test method Exec Method replace method)