Direct volume syntax
/pattern/attributes
To create the syntax for a RegExp object:
Copy code code as follows:
var obj=new regexp (pattern,attributes);
Case 1:
Copy code code as follows:
var pattern=/a/;
document.write (Pattern.exec ("Asdas"));
Case 2:
Copy code code as follows:
var obj=new regexp ("a");
document.write (Obj.exec ("Asdas"));
The execution results of Case 1 and Case 2 are the same;
Parameters
Parameter pattern is a string that specifies the schema or other regular expression of the regular expression.
The parameter attributes is an optional string that contains the property "G" (performs a global match lookup for all matches rather than stopping after the first match is found.) , "I": Performs a case-insensitive match. and "M": Perform multiple line matches. , used to specify global matches, case-sensitive matches, and multiple line matches, respectively. The M attribute is not supported until ECMAScript is standardized. If pattern is a regular expression, rather than a string, you must omit the argument.
return value
A new RegExp object with the specified pattern and flags. If parameter pattern is a regular expression instead of a string, the RegExp () constructor creates a new RegExp object with the same pattern and flags as the specified regexp.
If you do not use the new operator and RegExp () as a function call, its behavior is the same as when called with the new operator, except that when pattern is a regular expression, it returns only the formula and no longer creates a new RegExp object.