String.replace() : replace : String JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » String » replace »

 

String.replace()











Syntax








string.replace(regexpression, replacestring)



The replace() method searches the string for the regular expression passed to the method.

If a match is found, the method returns a new string with that match replaced with the replacement string passed to the method.

See the reference entry for RegExp.












<html>
    <script language="JavaScript1.2">
    <!--
    var myString = new String("This is a test");

    var myRegExp = /is/g;

    var newString = myString.replace(myRegExp, "test");

    document.write('Notice the last name in the original string, ' + myString);

    document.write(', was replaced and is now '+ newString);

    document.close();

    -->

    </script>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo String
» replace