Refresh

This website www.w3schools.blog/match-string-javascript-js is currently offline. Cloudflare's Always Online™ shows a snapshot of this web page from the Internet Archive's Wayback Machine. To check for the live version, click Refresh.

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: w3schools";
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>