Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find specific length numbers in a big document. I tried to use regex for this. For example, If I need to search for numbers with exactly 2 digits, I use /d/d (i.e. /d twice followed by a space). This works well.

But for finding 10 digit numbers it's not really feasible to type in /d 10 times.

Tried /d{2}, says 'E486: Pattern not found: \d{2}'

Is there any quicker/easier way to achieve this?

share|improve this question
up vote 10 down vote accepted

There are different regular expression dialects; some (e.g. Perl's) do not require backslashes in the quantification modifier (\d{2}), some (e.g. sed) require two (\d\{2\}), and in Vim, only the opening curly needs it (\d\{2}). That's the sad state of incompatible regular expression dialects.

Also note that for matching exact numbers, you have to anchor the match so that \d\{2} won't match to digits (12) in 123. This can be done with negative look-behind and look-ahead:

share|improve this answer
Perfect. Can you please one liner info on the regex? Would be really helpful. Thanks – mtk Sep 12 '13 at 9:08
For someone struggling with the basic regexp syntax, look-behind/ahead is pretty advanced. I probably cannot describe it better than the built-in :help /\@<! and :help /\@!. Don't worry if you don't immediately understand everything; as I said, this is pretty advanced. – Ingo Karkat Sep 12 '13 at 9:42
You can also put \v at the beginning of the regex if you wish to avoid having to escape the {, see :help magic for more information (it makes vim regex behave a bit more like perl regex, though there are still differences). – evilsoup Sep 12 '13 at 12:35
Thank god for them vim gurus. – Aki Sep 12 '13 at 14:43
Thank's a lot: \d\{4} in Vi it's a trivial one at all – installero Aug 15 '15 at 10:30

Escaping brackets works: \d\{2\}

share|improve this answer

Try the following:


and you should use \ not /

You can find out more about the regular exression of vim on this site or in vim with :help regular.

share|improve this answer

Not as pretty, but this worked for me for 5 digits in a log file.

share|improve this answer

Your Answer


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.