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
gattribute and therefore performs global matching.-
ignoreCase A read-only boolean that specifies whether the RegExp has the
iattribute 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
mattribute 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
stringagainst this RegExp and returns an array containing the results of the match, ornullif 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 anindexproperty that specifies the start position of the match.-
test(string) Returns
trueifstringcontains text matching this RegExp, orfalseotherwise.
See Also
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