JavaScript String search() method

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

Syntax:

string.search(regexp)

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

Return: It will return the position of the regular expression if it is present in the string otherwise returns -1.

Example:

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