This method returns the index where the match was found in the string. If no match is found, it returns -1.
Regexp − A regular expression object.
Substr − String to be replaced.
newSubStr − The replacement string.
function − the function to create a new string.
Returns the index at which the match was found in the string.
var str = 'Welcome to ES6.We are learning ES6'; var re = new RegExp(/We/); var found = str.search(re); console.log(found);