Returns the position of the first substring match in a regular expression search.
function search(rgExp : RegExp) : Number |
Arguments
- rgExp
-
Required. An instance of a Regular Expression object containing the regular expression pattern and applicable flags.
Remarks
The search method indicates whether a match is found. 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.
Example
The following example illustrates the use of the search method.
В | Copy Code |
---|---|
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 index to the first match //or –1 if no match is found. } |
Requirements
Applies To:
See Also
Reference
exec Methodmatch Method
Regular Expression Object
replace Method
test Method