1, REGEXP
- A pattern text for matching
- Matching pattern details described with 0 or more modifiers
form of RegExp object creation
- Create var re = new RegExp ("J.*t") with the built-in constructor
- The text is defined in the way var re =/j.*t/;
2. RegExp Object Properties
- G==>global: Whether the related search stops when the first match is found (false default)
- I==>ignorecase: Ignore case (false default)
- M==>multiline: Sets the option to search across rows, default to False
- LastIndex: Index location for search start, default to 0
- Source: The property used to store the regular expression matching pattern
- Except for lastindex, objects cannot be modified after they are created.
var re = new RegExp (' j.*t ', ' gmi ');
var re =/j.*t/ig;
2. Methods of RegExp objects
- Test () returns a Boolean value that is true when matching content is found
- EXEC () returns an array consisting of matching strings
/j.*t/.test ("Javascript") ==>false
/j.*t/i.test ("JavaScript") ==> true
/j.*t/i.exec ("Javscript") [0] ==> "Javascript"
- Match (): Returns an array containing the matching contents
- Search (): Returns where the first match is located
- Replace (): Replaces the matched text with the specified string
- Split (): Splits the target string into a number of array elements
var s = new String ("Hellojavascriptworld");
S.match (/a/); ==>["a"]
S.match (/a/g) ==>["A", "a"]
S.replace (/[a-z]/g, ') ==> "Elloavacriptorld"
Use $& to represent matching text when matching objects are found
S.replace (/[a-z]/g, ' _$&') ==> "_hello_java_script_world"//Match text before adding _
If the regular expression is divided into groups (with parentheses), the first group that matches the grouping is used, and so on
S.replace (/([A-z])/g,' _ $ ') ==> "_hello_java_script_world"//Match text before adding _
Note 007: Object--regexp Regular Expression object