The method match()
takes a regular expression (regex) and matches it against a provided string.
string.match(reg_exp)
reg_exp
: The regular expression that is matched against the string.
The match()
method returns an array containing the matches from the string.
Here is a coded example of the match()
method.
// lets look for all instances of 'ea' and 'in' in the following sentence.let str = "What a beautiful weather in Berlin.";console.log(str.match(/ea/g))console.log(str.match(/in/g))
Free Resources