Applies a regular expression to a string and returns an array of matches.
match()
uses regular expressions (regex) to match patterns in text. For example, the regex abc
can be used to search a string for the exact sequence of characters abc
. See MDN. for more information about regexes. matchAll()
is different from match() because it returns every match, not just the first.
The first parameter, str
, is the string to search.
The second parameter, regex
, is a string with the regular expression to apply. For example, calling matchAll('p5*js is easier than abc123', '[a-z][0-9]')
would return the 2D array [['p5'], ['c1']]
.
Note: If no matches are found, an empty array []
is returned.
उदाहरण
सिंटैक्स
matchAll(str, regexp)
पैरामीटर्स
str
String:
string to search.
regexp
String:
regular expression to match.
Returns
String[]: matches found.
Notice any errors or typos? Please let us know. Please feel free to edit src/utilities/string_functions.js and open a pull request!