2

I'd like to use [[:symbol:]]+ in a regular expression but this does not exist in Emacs, see ad-hoc section in the manual.

Q1: what is the rationale behind this? I'm always happy to understand the design decisions that gave us the beautiful beast that is emacs.

Q2: is there something that works like [:symbol:] would? At the moment I use ugly handmade regexes like [[:word:]_+=], listing just a few specific symbols that I know will occur in my application.

4

Q2: is there something that works like [:symbol:] would? At the moment I use ugly handmade regexes like [[:word:]_+=], listing just a few specific symbols that I know will occur in my application.

You could use the special \s syntax which references characters with a specific syntax class in a regular expression.

In your case, w is the syntax class of word constituents, and _ is the syntax class of additional symbol constituents. Which means that

\\(\\sw\\|\\s_\\)

matches any symbol constituent.

  • Great!!! I did not know about \s :-( That is very helpful.I'll accept your answer in a few days if no one addresses the 1st question. – phs Sep 11 '15 at 12:17
2

I can't enlighten you on Q1 either. You could always propose it as an addition.

Another approach to Q2 is to match the entire symbol by obtaining the text between a pair of symbol-beginning and symbol-end assertions:

"\\_<\\(.+?\\)\\_>"
  • Couldn't that match greedily several symbols on a same line? – phs Sep 11 '15 at 15:42
  • 1
    No. +? is non-greedy. – phils Sep 12 '15 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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