Class RegExp

The RegExp object is a static object that generates instances of a regular expression for pattern matching and monitors all regular expressions in the current window or frame. Consult ECMA standards for the format of the pattern strings supported by these regular expressions.

Property Summary 

PropertyDescription
global: BooleanIf the regular expression instance has the g modifier, then this property is set to true.
ignoreCase: BooleanIf the regular expression instance has the i modifier, then this property is set to true.
lastIndex: NumberThis is the zero-based index value of the character within the String where the next search for the pattern begins.
multiline: BooleanIf a search extends across multiple lines of test, the multiline property is set to true.
source: StringA String version of the characters used to create the regular expression.

Constructor Summary 

ConstructorDescription
RegExp(String)Constructs the regular expression using the specified pattern.
RegExp(String, String)Constructs the regular expression using the specified pattern and attributes.

Method Summary 

MethodDescription
exec(String)Performs a search through the specified parameter for the current regular expression and returns an array of match information if successful.
test(String)Returns true if there is a match of the regular expression anywhere in the specified parameter.

Methods inherited from class Object 

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Property Details 

global 

global: Boolean

If the regular expression instance has the g modifier, then this property is set to true.


ignoreCase 

ignoreCase: Boolean

If the regular expression instance has the i modifier, then this property is set to true.


lastIndex 

lastIndex: Number

This is the zero-based index value of the character within the String where the next search for the pattern begins. In a new search, the value is zero.


multiline 

multiline: Boolean

If a search extends across multiple lines of test, the multiline property is set to true.


source 

source: String

A String version of the characters used to create the regular expression. The value does not include the forward slash delimiters that surround the expression.


Constructor Details 

RegExp(String) 

RegExp(pattern: String)

Constructs the regular expression using the specified pattern.

Parameters:

  • pattern - the regular expression pattern to use.

RegExp(String, String) 

RegExp(pattern: String, attributes: String)

Constructs the regular expression using the specified pattern and attributes. See the class documentation for more information on the pattern and attributes.

Parameters:

  • pattern - the regular expression pattern to use.
  • attributes - one or more attributes that control how the regular expression is executed.

Method Details 

exec(String) 

exec(string: String): Array

Performs a search through the specified parameter for the current regular expression and returns an array of match information if successful. Returns null if the search produces no results.

Parameters:

  • string - the String to apply the regular expression.

Returns:

  • an array of match information if successful, null otherwise.

test(String) 

test(string: String): Boolean

Returns true if there is a match of the regular expression anywhere in the specified parameter. No additional information is available about the results of the search.

Parameters:

  • string - the String to apply the regular expression.

Returns:

  • true if there is a match of the regular expression anywhere in the specified parameter, false otherwise.