This is one of the additions to the String object to support regular expressions.
The character location where the match occurred is returned. If there is no match then the value -1 is returned instead.
If you use the global attribute ('g'), then it will be ignored.
This resets the lastIndex property of a RegExp object to 0.
Don't mix this search() method up with the search property that belongs to the Location object as they are totally different things. The temptation might be to refer to the position that the string search yielded as a location. This could be very confusing for someone working on your scripts later on.
myString = "JavaScript is good"; myResult = myString.search(/GOOD/i); document.write(myResult);
Prev | Home | Next |
String.replace() | Up | String.slice() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |