Name
String
Strings support four convenience methods for pattern matching. Each method takes a pattern argument, which may be a RegExp object, or a string containing a regular expression pattern.
Methods
search(pattern)Match
patternagainst the string, returning either the character position of the start of the first matching substring or-1.replace(pattern,replacement)Search the string for a match of
pattern, and replace the matched substring withreplacement. Ifpatternhas global mode set, all matches ofpatternare replaced. The replacement string may have$nconstructs that are replaced with the matched text of thenth capture group inpattern.match(pattern)Match
patternagainst the string, returning either an array or-1. Element 0 of the array contains the full match. Additional elements contain submatches from capture groups. In global (g) mode, the array contains all matches ofpatternwith no capture group submatches.split(pattern,limit)Return an array of strings broken around
pattern. Iflimitis included, the array contains at most the firstlimitsubstrings broken aroundpattern. Ifpatterncontains capture groups, captured substrings are returned as elements after each split substring.