Page 228 - Web_Application_v2.0_C12_Fb
P. 228

4.  The replaceAll() Method: The replaceAll() method replaces all occurrences of a specified value with another
                 value in a string.
              Example 34: To demonstrate the use of replaceAll method

                 <!DOCTYPE HTML>
                 <HTML>
                 <HEAD>
                 <TITLE>replaceAll() Method</TITLE>
                 </HEAD>

                 <BODY>
                 <H2>The replaceAll() Method</H2>
                 <P>The replaceAll() method replaces all matching values in a string.</P>
                 <P id="demo1"></P>
                 <SCRIPT>
                 var text = "I love Python ! Python is great!";
                 document.getElementById("demo1").innerHTML                 =     text.replaceAll("Python           ",
                 "JavaScript");
                 </SCRIPT>
                 </BODY>
                 </HTML>
              Output:

















              5.  The match() Method: The match() method searches a string for a match against a regular expression and
                 returns an array.
              Example 35: To demonstrate the use of match method

                 <!DOCTYPE HTML>
                 <HTML>
                 <HEAD>

                 <TITLE>match() Method</TITLE>
                 </HEAD>
                 <BODY>

                 <H2>The match() Method</H2>
                 <P>The match() method finds matches using a regex.</P>
                 <P id="demo1"></P>
                 <SCRIPT>

                226   Touchpad Web Applications (Ver. 2.0)-XII
   223   224   225   226   227   228   229   230   231   232   233