This is one of the additions to the String object to support regular expressions.
The matches are returned in an array with each match in a separate element. You can use this to strip numeric values out of a string containing words and numbers by looking for a pattern such as:
/\d+/g
This would yield all the numeric values from a string.
The g attribute affects whether a single item matches or whether all of them match.
When the g attribute is not used, the array object has an additional property named index, which contains the character location where the match occurred. It also has an additional property called input, which contains the original string that was searched for a match.
myString = "JavaScript is good"; myLocation = myString.search(/GOOD/i); document.write(myLocation);
Prev | Home | Next |
String.localeCompare() | Up | String.prototype |
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. |