JavaScript String match() method

The JavaScript string match() method determines a specified regular expression in a given string and returns that regular expression if a match occurs.

Note: To get all the matches we have to use a global modifier.

Syntax:

string.match(regexp)

Parameters: regexp: It represents the regular expression to be searched.

Return: Matched regular expression.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var a ="Best tutorial website: w3spoint";
document.write(a.match('co'));
document.write("</br>");
document.writeln(a.match(/web/));
document.write("</br>");
document.writeln(a.match(/web/i));
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com