Name
RegExp: regular expressions for pattern matching â ECMAScript v3: Object â RegExp
Literal Syntax
/pattern
/attributes
Constructor
new
RegExp(
pattern
,
attributes
)
Arguments
-
pattern
A string that specifies the pattern of the regular expression or another regular expression.
-
attributes
An optional string containing any of the âgâ, âiâ, and âmâ attributes that specify global, case-insensitive, and multiline matches, respectively. The âmâ attribute is not available prior to ECMAScript standardization. If the
pattern
argument is a regular expression instead of a string, this argument must be omitted.
Returns
A new RegExp
object, with
the specified pattern and flags. If the
pattern
argument is a regular
expression rather than a string, the RegExp( )
constructor creates a new
RegExp object using the same pattern and flags as the specified
RegExp. If RegExp( )
is called
as a function without the new
operator, it behaves just as it would with the new
operator, except when
pattern
is a regular expression; in
that case, it simply returns pattern
instead of creating a new RegExp object.
Throws
-
SyntaxError
If
pattern
is not a legal regular expression, or ifattributes
contains characters other than âgâ, âiâ, and âmâ.-
TypeError
If
pattern
is a RegExp object, and theattributes
argument is not omitted.
Instance Properties
-
global
Whether the RegExp has the âgâ attribute.
-
ignoreCase
Whether the RegExp has the âiâ attribute.
-
lastIndex
The character position of ...
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.