JavaScript search() Method
Complete RegExp Object Reference
Definition and Usage
The search() method is used to search a string for a specified value.
The search() method returns the position of the specified value
in the string. If no match was found it returns
-1.
This method supports regular expressions.
Syntax
stringObject.search(regexp)
|
Parameter |
Description |
regexp |
Required. A regular expression. |
Tips and Notes
Note: search() is case sensitive.
Example
In the following example we will search for "W3Schools":
<script type="text/javascript">
var str = "Visit W3Schools";
var patt1 = /W3Schools/;
var result = str.search(patt1);
document.write("Position: " + result + "<br />");
</script>
|
Try-It-Yourself Demos
search()
How to use search() to search a string using a regular expression.
Complete RegExp Object Reference
|
|
|
See why there are 20,000+ Ektron integrations worldwide.
Request an INSTANT DEMO or download a FREE TRIAL today. |
|
|
|