the above code runs as shown in Figure 8.1.
because "\" in a JavaScript string is an escape character, when you use an explicit constructor to create a RegExp instance object, you should replace "\" in the original regular expression with "\". For example, the two statements in code 1.2 are equivalent.
"\" In code 1.2 escape characters: 1.2.htm
<scriptlanguage= "JavaScript" >
var re1 = new RegExp ("\\d{5}");
var re2 =/\d{5}/;
alert ("re1=" +re1+ "\nre2=" +re2);
</script>
because the escape character in the regular expression pattern literal is also "\", if you want to match the literal character "\" in the regular expression, in the regular expression pattern text, as "\ \", you need to use the "\\\\" when you create the RegExp instance object in the form of an explicit constructor. To represent the literal character "\".
var re = newregexp (\\\\). 1 Properties of the RegExp object
the properties of the RegExp object are divided into static and instance properties. The following are described separately. 1.1 Static properties
(1) Index property. is the starting position of the first match for the current expression pattern, counting starting at 0. The initial value is-1, and the Index property will change each time a successful match is made.
(2) Input property. Returns the currently acting string, which can be abbreviated to $_, and the initial value is an empty string "".
(3) Lastindex property. Is the next position of the last character in the first match of the current expression pattern, counting from 0, often as the starting position for the search, with an initial value of-1, which indicates that the search starts at the starting position, and the Lastindex property value changes each time a successful match is made.
(4) Lastmatch property. is the last matching string for the current expression pattern, which can be abbreviated to $&. Its initial value is an empty string "". The value of the Lastmatch property changes each time a successful match is made.
(5) Lastparen property. If there is a $+ in the expression pattern, it is the substring that the last child match in the current expression pattern matches, and can be abbreviated to a string. Its initial value is an empty string "". Each time a successful match occurs, the value of the Lastparen property changes.
(6) Leftcontext property. Is all that is left of the last matching string in the current expression pattern, which can be abbreviated to $ ' (where "" is the inverted single quotation mark below "ESC" on the keyboard). The initial value is an empty string "". Each time a successful match is made, its property values change.
(7) Rightcontext property. is all content on the right side of the last matching string in the current expression pattern, which can be abbreviated to $ '. The initial value is an empty string "". Each time a successful match is made, its property values change.
(8) $1...$9 property. These properties are read-only. If there is a $1...$9 in the expression pattern, the value of the property is captured by the 1th to 9th child match. If there are more than 9 child matches, the $1...$9 property corresponds to the last 9 substring respectively. In an expression pattern, you can specify any number of child matches with parentheses, but the RegExp object can only store the result of the last 9 child matches. In an array of results returned by some methods of the RegExp instance object, the results of the child matches within all parentheses are obtained. 1.2 Instance Properties
(1) global property. Returns the state of the global flag (g) specified when the RegExp object instance was created. If the G flag is set when the RegExp object instance is created, this property returns True, otherwise it returns false, and the default value is False.
(2) ignorecase property. Returns the state of the ignorecase flag (i) specified when the RegExp object instance was created. If the I flag is set when the RegExp object instance is created, this property returns True, otherwise it returns false, and the default value is False.
(3) Multiline property. Returns the state of the multiline flag (m) specified when the RegExp object instance was created. If the M flag is set when the RegExp object instance is created, this property returns True, otherwise it returns false, and the default value is False.
(4) The Source property. Returns the expression text string specified when the RegExp object instance was created.