If a match is found, the search method returns an integer value that specifies the offset from the beginning of the string where the match occurred. If no match is found, it returns -1.
function SearchDemo()
{
var s = "is but a dream within a dream";
// Create the regular expression pattern.
var re = /dream/i;
// Search the string.
var r = s.search(re);
return(r);
// Output: 9
}