This is one of the additions to the String object to support regular expressions.
The search pattern locates matches, which are then replaced by the string value in the second argument.
The value is modified in place.
The replacement text can make use of the numbered sub-expression references and can use them in the replaced string.
// Simple replacement myString = "javascript, 'JAVASCRIPT', JavaScript"; myString.replace(/javascript/ig, "JavaScript"); document.write(myString); myString.replace(/^.*\'([^\']*)\'.*$/, "---''$1''---")
Prev | Home | Next |
String.prototype | Up | String.search() |
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. |