Replace part of a string based on a group of letters in the matched string - Javascript String

Javascript examples for String:replace

Description

Replace part of a string based on a group of letters in the matched string

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){// w ww  . j  a va  2 s.  c om
  regex=/(.*class=\'ss-)(.*?)(\'>)(.*?)(<\/.*)/;
        str="<i class='ss-icon'>this is a test</i><i class='ss-icon'>this is a test</i>";
        var newStr=str.replace(regex, "$1$4$3$5");
        console.log(newStr)
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials