search Method
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
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.
function SearchDemo()
{
var s = "is but a dream within a dream";
// Create regular the expression pattern.
var re = /dream/i;
// Search the string.
var r = s.search(re);
return(r);
// Output: 9
}
Requirements
Applies To:
See Also
Concepts
Reference
Change History
Date |
History |
Reason |
---|---|---|
March 2009 |
Modified example. |
Information enhancement. |