How to get the first matched number in a string using regex in JavaScript

2 Answers

0 votes
var s = "javascript01223c++3php500--9_8";

document.write(s.match(/[0-9]+/)); 
 
 
  
/*
run:
   
01223
      
*/

 



answered Aug 3, 2019 by avibootz
0 votes
var s = "javascript01223c++3php500--9_8";

document.write(/[0-9]+/.exec(s)); 
 
 
  
/*
run:
   
01223
      
*/

 



answered Aug 3, 2019 by avibootz
...