Name
RegExp — regular expressions for pattern matching
Inherits from
Object → RegExp
Literal Syntax
/pattern/attributes
Constructor
newRegExp(pattern,attributes)
Arguments
patternA string that specifies the pattern of the regular expression or another regular expression.
attributesAn 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
patternargument 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
SyntaxErrorIf
patternis not a legal regular expression, or ifattributescontains characters other than “g”, “i”, and “m”.TypeErrorIf
patternis a RegExp object, and theattributesargument is not omitted.
Instance Properties
globalWhether the RegExp has the “g” attribute.
ignoreCaseWhether the RegExp has the “i” attribute.
lastIndexThe character position of the last match; used for finding multiple matches in a string. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access