I'm trying to construct a regular expression that would match symbols, that is, things like function names and the like, according to current major mode settings (it's called syntax table if I remember correctly). After some investigation, I have found these useful regexps:
\_<
matches beginning of a symbol\_>
matches end of a symbol
Now I think I need to find out how to represent symbol-constituent
character. We have \w
for word-constituent characters, but I cannot find
anything for symbols. Regexp to match symbols should be something like
(assuming that \s
matches on symbol-constituent characters):
\_<\s+\_>
Am I missing something? How to match on symbols?
Note that matching on words does not work for me. Trivial example is
something like foo-bar
that is a symbol in Emacs Lisp mode, but not a word
(because -
is not a word-constituent character).
(re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" nil t)
. It works, but I wonder myself if there's a shorter way.\s
actually means, as it's entirely different to your assumption.\s
has any meaning in Emacs regexps, I just picked that symbol for example.