Returns the position of the first substring match in a regular expression search.
stringObj.search(rgExp)
The search method indicates if a match is present or not. If a match is found, the search method returns an integer value that indicates the offset from the beginning of the string where the match occurred. If no match is found, it returns -1.
The following example illustrates the use of the search method.
function SearchDemo(){ var r, re; //Declare variables. var s = "The rain in Spain falls mainly in the plain."; re = /falls/i; //Create regular expression pattern. r =s.search(
re)
; //Search the string. return(r); //Return the Boolean result. }
exec Method | match Method | Regular Expression Object | Regular Expression Syntax | replace Method | String Object Methods | test Method
Applies To: String Object