Use Regex to replace a string with substring variable - Javascript String Operation

Javascript examples for String Operation:String Replace

Description

Use Regex to replace a string with substring variable

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 w w .  jav  a2 s  .co m
var input = '/html/body/div[3]/div[20]/section[1]/p[5]/span[1][@id="var123456"]/span';
console.log(input);
var regex = /\w+\[\w+\]\[\@id="var12345"\]\//gi;
input = input.replace(regex, '');
console.log(input);
    }

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

Related Tutorials