JavaScript search() Method
JavaScript String Object
Definition and Usage
The search() method searches for a match between a regular expression and a string.
This method returns the position of the match, or -1 if no match is found.
Syntax
| stringObject.search(regexp) |
Examples
Example 1
Perform a case-sensitive search:
<script type="text/javascript">
var str="Visit W3Schools!";
document.write(str.search("W3SCHOOLS"));
</script>
|
The output of the code above will be:
Try it yourself »
|
Example 2
Perform a case-insensitive search:
<script type="text/javascript">
var str="Visit W3Schools!";
document.write(str.search(/w3schools/i));
</script>
|
The output of the code above will be:
Try it yourself »
|
JavaScript String Object
Click here to design a Stunning Flash Website for Free
Wix is a revolutionary web design tool that provides anyone with the possibility to create professional and beautiful websites for free.
With e-commerce features, search engine visibility and many more professional tools, Wix is the ultimate solution for creating a spectacular site while saving tons of money.
|