0

I'm struggling to find a correct regexp to match quoted symbol inside a string:

" 'foo " or " 'foo.bar "

Any help will be appreciated

  • Why do you need a regexp to match a single character? Can you give examples of what should and should not be matched? – sds Jan 2 at 21:11
  • 1
    Please give more context. What do you want to achieve? The regular expression matching a single quote without the consideration of boundaries is a single quote. If you put that regular expression into a string you get "'". You certainly already tried that one. So the context is important here. – Tobias Jan 2 at 21:13
  • I'm sorry, i've been misleading: i'm trying some code highlighting stuff for clojure, and would like to assign a fontface to litteral symbols. I've finally found something that work for me for now (I'm a total noob in elisp regexp) – szymanowski Jan 2 at 21:53
  • @szymanowski -- the best way is to write an elisp function that search for QUOTE+SYMBOL, then check that the found string is inside a string using syntax-ppss (if it's not then continue searching). In the font-lock rule, specify the elisp function as MATCHER, instead of your regexp. – Lindydancer Jan 2 at 21:58
1

Note: The question originally asked how to match quoted symbols.

Only strings can be matched. Use symbol-name to convert symbols to strings.

(let ((s 'bar.baz))
  (string-match "az" (symbol-name s)))
  • I'm sorry i've been misleading, I would like to match "'bar.baz" not "bar.baz" (notice that first string begins with a single quote) – szymanowski Jan 2 at 21:05
  • @szymanowski: Please don't change the question substantially after a response has been given. It makes the reply worthless. You can always ask a new question. – choroba Jan 2 at 21:13
  • i'm sorry, i should not have done that, it was implicit to me that one can only match string (to give you more context, i'm trying some code highlighting stuff for clojure, and would like to assign a fontface to litteral symbols) – szymanowski Jan 2 at 21:48
  • @szymanowski Literal symbols occur in setq without the quotes. There are more compilcated cases where literal symbols do not have a leading quote. It is not sufficient to search for quotes. You also need to check whether the quote occurs in a comment or string (maybe with syntax-ppss if comment-use-syntax is non-nil for clojure-mode). – Tobias Jan 3 at 9:15
  • @tobias,thank you for the extra considerations, it is useful! – szymanowski Jan 3 at 9:39

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.