This article shares with you the main isJavascript the reference typeRegExp related content, take a look at it, hope to everyone Learning JavaScript has helped. · literal quantity var Reg=/\d+/g; Console.log ( Reg. Test ("789456"));//true · constructor Function varReg2=NewREGEXP ("\\d+", "G"), Console.log (Reg2.test ("1234444456")),//trueconsole.log (Reg2.test ("ASDSA"));//false modifier · i: indicates case insensitive (Case-insensitive mode, which ignores the case of the pattern and string when the match is determined; · m: represents multiple lines (Multiline mode, that is, when the end of a line of text is reached, it also continues to find out if there are items in the next row that match the pattern. · g: represents a global (Global mode, that is, the pattern will be applied to all strings instead of stopping immediately when the first occurrence is found; Meta character · Single character number · . match any character other than line break · [A-za-z0-p] with the [^a-za-z0-p] matches any character in the square brackets, and the preceding generation ^ matches any character that is not in square brackets; · \d with the \d match numbers and match non-numbers; · \w with the \w match characters and match non-letters · White space characters · \o Match NULL character · \b Match space character · \f match a page break · \ n Match line break · \ r Match carriage return character · \s and the \s matches white space characters, spaces, tabs, or line breaks. In uppercase S matches a non-null character · \ t Match Tabs · Locator Characters · ^ Start line Match · $ End-of- line matching · \a matches only the beginning of a string · \b \b match words conveniently, words in [] invalid, match non-word boundary · G match the starting position of the current search · \z \z matches the end of a string or the end of a line, matching only the ending of a string · Qualifier · X? Match 0 one or a x · x* Match 0 or any number of x · x+ match one or more · X{m,n} Match M-n a x ; · Grouping · (?: x) Match x but no matching results are recorded (match not captured) · X (? =y) when x Back up y when matching x · X (?! Y when x after not y when matching x · References · \1...\9 $1...$9 returns the most recently saved part of the cut that was found during pattern matching · or Mode · X|y|z Match x or y or Z Properties Instance Properties Regexp Each instance has the following properties, which enable you to obtain various information about the pattern. · Global : Boolean value, detection is Go Set g Mark · IgnoreCase : Boolean value that detects whether the setting I Mark · Nultiline : Boolean value that detects whether the m Mark · LastIndex : An integer that represents the character position at which to start searching for the next occurrence, from 0 count. · Source returns a string representation of a regular expression , returned in literal form rather than in the string pattern in the incoming constructor. These properties allow you to learn about the various aspects of a regular expression, but it is of little use because it is all contained in a schema declaration. varPATTERN1 =/\[bc\]at/i;console.log (Pattern1.global); Falseconsole.log (pattern1.ignorecase); Trueconsole.log (Pattern1.multiline); Falseconsole.log (Pattern1.lastindex); 0console.log (Pattern1.source); "\[bc\]at" varPATTERN2 = NewREGEXP ("\\[bc\\]at", "I"); Console.log (Pattern2.global); Falseconsole.log (pattern2.ignorecase); Trueconsole.log (Pattern2.multiline); Falseconsole.log (Pattern2.lastindex); 0console.log (Pattern2.source); "\[bc\]at"Although the first pattern uses the literal, the second pattern uses theRegexp constructors, but their Source the properties are the same. Visible, Source property holds a string in canonical form, that is, the string used in the literal form. Constructor Properties · $_ input returns the most recently matched string · $& lastmatch returns the last occurrence · $+ Lastparen returns the most recent matching capture group · $ ' leftcontext returns the character from the beginning of the string in the searched string to the position before the last match · $ ' rightcontext returns the character from the last matching position in the searched string to the end of the string · $* Multiline detect if an expression is matched with multiple lines m Method instance Method Test () method detects pattern matching in a string and returns true or false varre = null, I; for(i = 0; i < i++) { re =/cat/g; Console.log (Re.test ("catastrophe")); True } for(i = 0; i < i++) { Re = NewREGEXP ("Cat", "G"); Console.log (Re.test ("catastrophe")); True } Regexp The main method of the object is exec () , the method is specifically designed for capturing groups. exec () accepts a parameter, which is the string to which the pattern is to be applied, and then returns an array that contains the first match information, or returns if no match is found NULL . The returned array, although Array instance, but contains two additional attributes: Index and the input . Among them, Index represents the position of a match in a string, and input A string that represents the application of a regular expression. In the array, the first item is a string that matches the entire pattern, and the other item is a string that matches the capturing group in the pattern (if there is no capturing group in the pattern, the array contains only one item). varText = "Cat, bat, Sat, fat"; varPATTERN1 =/.at/; varmatches = pattern1.exec (text); Console.log (Matches.index); 0console.log (Matches[0]); Catconsole.log (Pattern1.lastindex); 0 matches = pattern1.exec (text); Console.log (Matches.index); 0console.log (Matches[0]); Catconsole.log (Pattern1.lastindex); 0 varpattern2 =/.at/g; varmatches = pattern2.exec (text); Console.log (Matches.index); 0console.log (Matches[0]); Catconsole.log (Pattern2.lastindex); 3 matches = pattern2.exec (text); Console.log (Matches.index); 5console.log (Matches[0]); Batconsole.log (Pattern2.lastindex); 8First ModePattern1 is not a global mode, so each call exec () returns the first occurrence of a match ( "Cat" ). and the second pattern pattern2 is the global schema, so each call exec () will return the next occurrence in the string until the end of the string is searched. In addition, you should pay attention to the pattern LastIndex the change of the property. In global match mode, LastIndex value in each call to the exec () is incremented and remains unchanged in non-global mode. String Method · Match find a match for one or more regular expressions · Replace to replace a substring that matches a regular expression · Search retrieving a value that matches a regular expression · Split To split a string into an array of stringsSource: liuguoquan727
JavaScript Reference type RegExp