Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to get the regex-pattern for the following sequence of numbers:

X.XXX.XXX-X 

Every X is one number.

How can I do that? I don't want to use *, because I need exactly the number of numbers.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Use braces to specify the number of occurrences:

\d{1}\.\d{3}\.\d{3}-\d{1}

{3} will match the previous token exactly 3 times. You can also specify a range like {1,5} which will match the previous token between 1 and 5 times. This is a greedy match and will match as many characters as possible.

share|improve this answer
    
Thank you. It worked –  c0dev Nov 6 '13 at 10:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.