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

2 Answers

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

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

 



answered Aug 2, 2019 by avibootz
0 votes
var s = "javascript";

document.write(s.search(/[0-9]+/)); // not matched = -1
 
 
  
/*
run:
   
-1
      
*/

 



answered Aug 2, 2019 by avibootz
...