The basic points of JS regular expression

Source: Internet
Author: User

/** JS Regular expression * JS in two ways of using the regular: * 1, Test () to determine whether the given string contains the specified rules of the string * 2, EXEC () Remove the specified rule string in the given string*/varText = "ASSDFDSTEST_10_ASTEST20ASD";//The First kind:/.. /Match only the first matchvarPattern =/\d+/;//pattern.test (text); TruePattern.exec (text);//[' Ten ']//The second kind:/. /g matches all occurrences of the entire stringvarPattern =/\d+/g;pattern.exec (text); //[' Ten ']Pattern.exec (text);//[' + ']Pattern.exec (text);//[' null '] null after the continuation of the fetch will continue starting from 10//The Third Kind:/.. /I ignores casevarPattern =/test/gi;pattern.exec (text); //[' Test ']Pattern.exec (text);//[' Test ']Pattern.exec (text);//NULL//Fourth type:/.. /m multi-line matching, so that the ' ^ ' symbol can match multiple lines within a single string//The default is multi-line matching, but if you add ' ^ ' to match only the beginning of a single line, use//m to let ' ^ ' match multiple lines beginningvarText1 = "JavaScript is more fun than Java and JavaBean.";varPattern =/^java\w*/g;pattern.exec (Text1); //[' JavaScript ']Pattern.exec (Text1);//NULLvarText2 = "JavaScript is more fun than \njava and JavaBean.";varPattern =/^java\w*/gm;pattern.exec (TEXT2); //[' JavaScript ']Pattern.exec (TEXT2);//[' Java ']Pattern.exec (TEXT2);//NULL//grouping facilitates the re-operation of matchesvarPattern =/java (\w*)/;//grouping is in matching results, matching matches in parenthesesPattern.exec (Text1);//[' JavaScript ', ' Script ']

The basic points of JS regular expression

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.