Regex to match 10 or 12 digits only

python-2.7, regex

Solution

You're close!

This is the regex you're looking for: `^(\d{10}|\d{12})$`. It checks for digits (with `\d`). The rest is more or less your code, with the exception of the parenthesis. It captures each group. You could loose those, if you want to work without it!

See it in action here

Problem

I tried to write a regex to match a 10 or 12 digits number combination. like: 1234567890 - True 123456789012 - True 12345678901 - False 123456- False 1234567890123- False Only match either 10 or 12 digits. I tried this: ``` "^[0-9]{10}|[0-9]{12}$" ```

Original source