Find number inside [] with regex - Javascript RegExp

Javascript examples for RegExp:Match Number

Description

Find number inside [] 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() {//from ww w  .  ja  va  2s. co  m
var string = "[Name_is][234]"
var matches = string.match(/\[(\d+)]/);
if (matches.length) {
    var num = matches[1];
    console.log(num);
}
    });

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

Related Tutorials