Name
RegExp
Synopsis
/pattern
/attributes
Constructor
new RegExp(pattern
,attributes
)
Regular expression patterns are expressed using a complex grammar that is summarized earlier in this chapter (Section 11.2.12).
Instance Properties
-
global
A read-only boolean that specifies whether the RegExp has the
g
attribute and therefore performs global matching.-
ignoreCase
A read-only boolean that specifies whether the RegExp has the
i
attribute and therefore performs case-insensitive matching.-
lastIndex
For global RegExp objects, this read/write property specifies the character position immediately following the last match; this is the first character examined for the next match.
-
multiline
A read-only boolean that specifies whether the RegExp has the
m
attribute and therefore performs multi-line matching.-
source
A read-only string that holds the source text of the regular expression
pattern
, excluding slashes and attributes.
Methods
-
exec(
string
)
Matches
string
against this RegExp and returns an array containing the results of the match, ornull
if no match was found. Element 0 of the array is the matching text. Subsequent elements of the array contain the substrings that matched the subexpressions within the RegExp. The returned array also has anindex
property that specifies the start position of the match.-
test(
string
)
Returns
true
ifstring
contains text matching this RegExp, orfalse
otherwise.
See Also
Get Webmaster in a Nutshell, Third 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.