Write regex to match 10 digits only from a string but exclude spaces

4.24K viewsProgrammingalgorithms javascript regex string
0

How can I write regex to match 10 digits from a string but exclude any number of spaces in between.

Answered question
0

Here it is:-

/^(\s*\d\s*){10}$/g
 example below:
 init();
   //(^[0-9]+(\s*[0-9]+)*$){0,10}
   function init() {
  var str = '0 12 34567 8    9';
     console.log(str.match(/^(\s*\d\s*){10}$/g)); 
 }

Answered question
Write your answer.

Categories