Search for "W3Schools":
The result of n will be:
More "Try it Yourself" examples below.
The search() method searches a string for a specified value, and returns the position of the match.
The search value can be string or a regular expression.
This method returns -1 if no match is found.
Read more about regular expressions in our RegExp Tutorial and our RegExp Object Reference.
Method | |||||
---|---|---|---|---|---|
search() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
searchvalue | Required. A regular expression. A string will automatically be converted to a regular expression. |
Return Value: | A Number, representing the position of the first occurrence of the specified searchvalue, or -1 if no match is founds |
---|---|
JavaScript Version: | 1.2 |
Perform a case-sensitive search:
The result of n will be:
Perform a case-insensitive search:
The result of n will be: