match

– The match() method retrieves the matches when matching a string against a regular expression. Returns a Array of matches or null of none is found.
– Format: str.match(regex)
– Same as RegExp.exe() if regexp doesn’t have the /g flag
– Example:
var regex = /(.)\1+/g;
var str = “aab”;
console.log(str.match(regex));

logs [ ‘aa’, index: 0, input: ‘aab’ ]

Leave a Reply

Your email address will not be published. Required fields are marked *