If you're entering the regex interactively, and want to use {3}
, you need to use backslashes to escape the curly braces. If you don't want to match any part of the longer strings of numbers, use \b
to match word boundaries around the numbers. This leaves:
\b[0-9]\{3\}\b
For those wanting more information about \b
, see the docs:
matches the empty string, but only at the beginning or end of a word. Thus, \bfoo\b
matches any occurrence of foo
as a separate word.
\bballs?\b
matches ball
or balls
as a separate word.
\b
matches at the beginning or end of the buffer regardless of what text appears next to it.
If you do want to use this regex from elisp code, as always, you must escape the backslashes one more time. For example:
(highlight-regexp "\\b[0-9]\\{3\\}\\b")