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

Member

by domenico , in category: Third Party Scripts , 5 months ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , 5 months 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.

Related Threads:

How to replace "$10" with "10 dollars" using regex?
How to replace spaces between words using regex?
How to allow multiple spaces in between the text using regex?
How to match regex in python?
How to not match substrings with regex?
How to match with "\*" but not with "/\*" in regex?