I have made a face to highlight elisp comments starting with ;; [ using hi-lock. My intention is to only colour the expression [text] using SUBEXP.

(highlight-regexp "^;; \\[.+\\].+$" 'face-aid "\\[.+\\]"))

Tho above does not do the highlight. How does one construct SUBEXP exactly?

The documentation for highlight-regexp states that the function limits face setting to the corresponding SUBEXP of REGEXP. But does not say how a SUBEXP would look like. Using "\\[.+\\]" for SUBEXP is definitely incorrect.

  • 2
    And what is the question? Dec 11, 2022 at 8:59
  • How to define subexp in highlight-regexp.
    – Dilna
    Dec 11, 2022 at 9:11
  • 1
    Then edit your question to ask that! Dec 11, 2022 at 10:41
  • It's not clear what's unclear to you. Answering your question by just quoting the doc would seem to answer it. Assuming you've read the doc, that's apparently not the case, so just what your problem is isn't clear from the question. What part of the description of SUBEXP do you have trouble understanding?
    – Drew
    Dec 12, 2022 at 18:16

1 Answer 1


By SUBEXP a match group is meant. Match groups are defined by \\( ... \\) and they are numbered 0 (for the whole match), 1 (for whatever is within the first \\( ... \\), etc.

So the following would apply the face only to the match group 1:

(highlight-regexp "^;; \\(\\[.+\\]\\).+$" 'error 1)
  • 1
    You've got a typo: \(( ... \\) instead of \\( ... \\). (I'd make an edit but given my rep on this stack, I can only suggest an edit of 6+ characters, but this is only a change of 2-4 characters.)
    – mtraceur
    Apr 14, 2023 at 7:23

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.