match()

Applies a regular expression to a string and returns an array with the first match.

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.

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 match('Hello, p5*js!', '[a-z][0-9]') would return the array ['p5'].

Note: If no matches are found, null is returned.

उदाहरण

सिंटैक्स

match(str, regexp)

पैरामीटर्स

str
String:

string to search.

regexp
String:

regular expression to match.

Returns

String[]: match if 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!

संबंधित संदर्भ