Increase each number in a string with regex - Javascript RegExp

Javascript examples for RegExp:Match Number

Description

Increase each number in a string with regex

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 .  ja va2 s.  c  o  m
console.log("test[test][1][name][2]".replace(/\[(\d+)\]$/g, function(match, number) {
    return "[" + (Number(number) + 1) + "]";
}));
    });

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

Related Tutorials