JS Regular expression 1; (basic syntax, test method Exec Method replace method)

Source: Internet
Author: User

//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)

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.