10.1 Regular Expressions
10.1.1 Direct Volume characters
<script type= "Text/javascript" > var pattern =/s$/; Console.log (Object.prototype.toString.call (pattern)); Console.log (typeof pattern); // ^$.*+?=!:| \ \ () []{}</script>
View Code
10.1.2 Character class
<script type= "Text/javascript" >//The character class (character Class) is formed by placing the direct volume character in square brackets, and a character class can match any character it contains //any character in square brackets [...] //[^ ...] any character not in square brackets //. Any character except newline characters and other Unicode line terminators //\w A word that consists of any ASCII character, equivalent to [a-za-z0-9] //\w Any word that is not an ASCII character, equivalent to [^a-za-z0-9] //\s Any Unicode whitespace character //\s any non-Unicode whitespace characters, note that \w and \s are different //\d any ASCII number, equivalent to [0-9] //\d any character except ASCII digits, equivalent to [^0-9] //[\b] push lattice direct volume</script>
View Code
10.1.3 Repeat
<script type= "Text/javascript" > //{n,m} matches the previous item at least n times, but not more than M //{n,} match previous N or more times // {n} matches the previous item n times //? Match the previous item 0 or 1 times, which means the previous item is optional, equivalent to {0,1} //+ Matches the previous item 1 or more times, equivalent to {1,} //* matches the previous item 0 or more times, equivalent to {0,} /\d{2,4}/ /\w{3}\d?/ /\s+java\s+/ /[^ (]*/</script>
View Code
10.1.4 selection, grouping and referencing
<script type= "Text/javascript" > // Regular expression syntax also contains the specified selection, sub-expression grouping, and referring to the special characters of the previous sub-expression // | Select to match the subexpression to the left of the symbol or to the right sub-expression //(...) combination, combining several items into a single unit, which is available through "*", "+", "?" and "|" Such symbols are modified // and the strings that match this combination can be remembered for subsequent references using //(?...) only combinations, Combine items into a single cell, but do not remember matching characters in the group //\ n and nth grouping the first matching characters, the group is a subexpression in parentheses (also possibly nested), the group index is left-to-right, the number of left parenthesis, " (?: "Form of grouping does not encode </script>
View Code
10.1.5 Specifying a matching location
<script type= "Text/javascript" > //^ matches the beginning of the string, in a multiline search, matches the beginning of the line //$ Matches the end of the string, in a multiline search, the end of the match line //\b matches the boundary of a word, in short, the position between the character \w and \w, or the position between the character \w and the beginning or end of the string //\b matches the position of a non-word boundary // (? =p) 0 wide forward predicate assertion, to go to the next character all matches p, but cannot include those characters that match p // (?! P) 0 Wide negative forward assertion, requires the next character not P-match </script>
View Code
10.1.6 modifier
<script type= "Text/javascript" > //I performs a case-insensitive match //G performs a global match, in short, That is to find all matches, instead of stopping //m Multi-line matching pattern after finding the first one, ^ matches the beginning of a line and the beginning of the string, the end of the matching line and the end of the string </script>
View Code
10.2 String method for pattern matching
<script type= "Text/javascript" > console.log ("JavaScript". Search (/script/i)); // returns the starting position of the first substring to match, and returns 1 if no matching substring is found // var text; // Text.replace (/javascript/gi, "JavaScript"); // var quote =/"([^"]*) "/g; // text.replace (Quote, ' "$"); // Match // Splite</script>
View Code
10.3 RegExp Object
10.3.1 Properties of RegExp
<script type= "Text/javascript" > / / Each RegExp object contains 5 properties //source A read-only string that contains the literal //Global Read-only Boolean value of the regular expression to indicate whether the regular expression has a modifier g // IgnoreCase Read-only Boolean value that indicates whether the regular expression has a modifier i //Multiline Read-only Boolean value that indicates whether the regular expression has a modifier m ///LastIndex This property is stored at the beginning of the next retrieval of the entire string </script>
View Code
Methods of 10.3.2 RegExp
<script type= "Text/javascript" > //regexp.exec () //regexp.test () //regexp.search (); // regexp.replace () // Regexp.match (); </script>
View Code
10th-Regular Expressions