Output the first character that causes mismatch with a regular expression - Javascript RegExp

Javascript examples for RegExp:RegExp Match

Description

Output the first character that causes mismatch with a regular expression

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   w w w  . j  a  v a2 s.  c om*/
var s = "123a45";
console.log(s.substr(s.match(/^(\d{3}\s\d{2}|\d{3}\s\d|\d{3}\s|\d{0,3})/)[1].length,1));
    });

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

Related Tutorials