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