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

3.47K 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
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.

Categories