match and replace a string - Javascript String Operation

Javascript examples for String Operation:String Replace


match and replace a string

Demo Code

ResultView the demo in separate window

      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from  w w  w  .j  a  va 2  s . c o  m
var str="itss[BACK][BACK][BACK][BACK][BACK][BACK] test test test test test [BACK][BACK]";
var backspaces = str.match(/\[BACK\]/g).length;
for(i=0; i<backspaces; i++)
    str = str.replace(/.?\[BACK\]/, '');
document.write( str );


Related Tutorials