A regular expression object is used to regulate a standard expression (that is, the expression operator does not meet specific requirements, such as whether it is an email address format or not ), it has the attributes and methods used to check whether the given string meets the rules.
In addition, the attributes of individual regular expression objects created using the Regexp constructor have pre-defined static attributes of Regular Expression objects, and you can use them at any time.
Text format or Regexp constructor function.
The text format is as follows:
The constructor function method is as follows:
New Regexp ("pattern" [, "Flags"]) is new Regexp ("Mode" [, "flag"])
Indicates the text of a regular expression.
If this option is specified, flags can be one of the following nominal values:
G: Global match (exact match)
I: Ignore case (case insensitive)
GI: both global match and ignore case (matching all possible values, Case Insensitive)
Note: Do not Mark parameters in text format with quotation marks, while parameters in constructors must be marked with quotation marks. Therefore, the following expression creates the same regular expression:
/AB + C/I
New Regexp ("AB + C", "I ")
When using constructor, you must use a normal string to avoid rules (adding the leading character \ To the string.
For example, the following two statements are equivalent:
Re = new Regexp ("\ W + ")
Re =/\ W +/