\d metacharacters + quantifiers \w commonly used characters a-za-z0-9. Characters other than carriage return? 0-1 character quantifier Only the preceding is a meta-character, the quantifier * 0-n quantifier/^\d+$/begins with a character, the end of a literal character [0-9] an element replace,exec,matchvar str= "ADFDFSAAADFDAAFSAA"; Str.replace (' A ', ' * '); Str.replace (/a/g, ' * '); var i=0;str.replace (/a/,function (s) {return i++;return S;}); --s is a--replace custom substitution rule before each replacement--can be customized to return something var a=["0", "one", "II", "three", "WU", "Lu", "Qi", ba "," JIU "," pick "];var str= ' 887284 '; var Result=str.replace (/\d/g,function (str,i,input) {///First parameter: The result of a regular match example: The first result is a number 8//the second parameter: the position of the current STR//input: the currently entered string The following two parameters generally do not return A[STR];}); /group replace has four parameters more than a few groups, more than a few parameters var Result=str.replace (/(\d)/g,function (str,sl,i,input) {///The first parameter: The result of a regular match example: The first result is a number 8//second parameter: current str position//input: The current input string after two parameters generally do not use//group always in the middle I and input always in the penultimate and first position return A[STR];}); var str= "My name is{0}. I Am{1} years old. I am in Class{2} grade{3} "; var a=[" Cupid ", 38,4,6];str.replace (/{(\d)}/g,function (str,) {console.log (str);//{0},{1},{ 2},{3}console.log (SZ);///Group 0,1,2,3onsole.log (regexp.$1);//Group 0,1,2,3retur A[sz];//return a[regexp.$1];//});
Javascript Regular Expression notes