Javascript examples for String Operation:String Replace
match and replace a string
<html> <head> <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 ); }); </script> </head> <body> </body> </html>