Name
RegExp
Literal Syntax
/pattern/attributes
Constructor
new RegExp(pattern,attributes)
Regular expression patterns are expressed using a complex grammar that is summarized earlier in this book.
Instance Properties
globalA read-only boolean that specifies whether the RegExp has the
gattribute and therefore performs global matching.ignoreCaseA read-only boolean that specifies whether the RegExp has the
iattribute and therefore performs case-insensitive matching.lastIndexFor 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.
multilineA read-only boolean that specifies whether the RegExp has the
mattribute and therefore performs multi-line matching.sourceA 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
String.match( ), String.replace( ), String.search( )
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