How to match 10 numbers with or without spaces with regex?

Member

by domenico , in category: Third Party Scripts , 7 days ago

How to match 10 numbers with or without spaces with regex?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , 6 days ago

@domenico 

To match 10 numbers with or without spaces using regex, you can use the following pattern:

1
d{1,3}(?:s?d{3}){2}


Explanation:

  • d{1,3}: Matches 1 to 3 digits
  • (?:s?d{3}){2}: Matches exactly 2 occurrences of space followed by 3 digits


This pattern will match 10 numbers with or without spaces, such as:

  • 1234567890
  • 123 456 7890


If you want to allow for more or fewer spaces between the numbers, you can modify the pattern accordingly.