Parameters: Here the parameter is “regExp” (i.e. regular expression) which will compare with the given string.
Return Value: It will return an array that contains the matches one item for each match or if the match will not found then it will return Null.
Input: var string = Welcome to geeks for geeks! document.write(string.match(/eek/g); Output: eek, eek
In the above example, substring “eek” will match with the given string, and when a match is found, it will return an array of string objects. Here “g” flag indicates that the regular expression should be tested against all possible matches in a string.
Input: var string = "Welcome to GEEKS for geeks!"; document.write(string.match(/eek/i); Output: EEK
In the above example, the substring “eek” will match with the given string, and it will return instantly if it found the match. Here “i” parameter helps to find the case-insensitive match in the given string.
Input: var string = "Welcome to GEEKS for geeks!"; document.write(string.match(/eek/gi); Output: EEK, eek
In the above example, the substring “eek” will match with the given string, and it will return instantly if it found the match. Here “gi” parameter helps to find the case-insensitive match AND all possible combinations in the given string.
- chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 4 and above
- Opera 4 and above
- Safari 1 and above