I am using highlight-regexp with a regexp pattern that includes the elisp comment characters ;;. How can I extend the pattern so that it adequately handle the general comment character for each language?

   "^;;\s+\\(\\[.+\\]\\).*$" 'kmface 1))

I have found comment-start but do not know how to use it in the regexp


Have started with format to try getting two comment characters next to each other to construct a regexp.

(let ((fm (format "%s%s" comment-start comment-start)))
    (message "fm: %s" fm))

1 Answer 1


You asked the same question on [email protected]. Thibaut Verron gave you the answer there. Repeating it here, for the benefit of others:

Use \s< to match the comment-start character, whatever it may be in the current mode. If you want two successive comment-start chars, use \s<\{2\}.

So your example would be:

(highlight-regexp "^\\s<+\\(\\[.+\\]\\).*$" 'kmface 1))

Or if you want only two comment-start chars, as you later stipulated, then:

(highlight-regexp "^\\s<\\{2\\}\\(\\[.+\\]\\).*$" 'kmface 1))

(You need to double backslash chars in Lisp strings.)

See the Elisp manual, node Regexp Backslash, which tells you that \sC matches a character with syntax class C. And see node Syntax Class Table, which tells you that < designates the comment-start syntax class.

So \s< matches a comment-start character.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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