Javascript Regular Expression notes

Source: Internet
Author: User

\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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.