Using the search() Method
Unlike indexOf(), the search() method takes a regular expression as argument; the regular expression can be case-insensitive, but cannot be global: it will only return the character position index of the first pattern matched.
Handling Unsuccessful Matches with the search() Method
Because the search() method returns predictable results in case of failed searches, unsuccessful matches are easy to handle appropriately:
var carter = "VBScript isn't an ideal language for the web.";
We know that the search() method returns -1 in case of failed match, so we could display an informative message:
Test the search() Method