tags:

views:

132

answers:

3

I often wish to search for variables that are simply called 'c' or 'count'.

For example

int c, count;

Unfortunately when I use an incremental search for 'c' or 'count' I get a lot of unnecessary hits like the 'c' in 'choice', or the 'count' in 'wordcount' which do not interest me. I know Emacs can do i-searches with regular expressions but I don't know the correct regular expression needed to match just 'c' and 'count'. These words are often surrounded by any number of white spaces. Anyone know the regex I can use to narrow my search?

+7  A: 

Use isearch-forward-regexp, usually bound to C-M-s, and search for \bc\b or \bcount\b

Andrew Stein
+2  A: 

You want to search (isearch-forward-regexp) for your string with word-boundaries (\b) on either side:

\bc\b

\bcount\b
Jeff B
+6  A: 

In Emacs23, there's M-x isearch-forward-word (bound to M-s w) which does takes care of the word boundary (at the front) for you.

M-s w count

And, another keyboard shortcut for Andrew Stein's answer of using isearch-forward-regexp is C-u C-s.

Trey Jackson