2

Is there a way, that each group in regexp can be highlighted with a different color.

For example, if I am searching for

\(text_part_1\)\|\(text_part_2\)

Can the text_part_1 be highlighted in one color and text_part_2 in another color?

  • 1
    Are you stuck on using Helm, here? If you are open to other possibilities, Icicles search does exactly what you are asking. – Drew Dec 3 '17 at 15:21
  • Yes, I am open to other possibilities. The documentation screenshot shows exactly what I want. I will try it and close this. Thanks a lot. – Shankar Ramakrishnan Dec 3 '17 at 16:43
  • No need to close the question. You will no doubt get good answers, including about using Helm for this. I will add an answer that mentions Icicles support for it. And I imagine there are other approaches, with or without Helm. – Drew Dec 3 '17 at 18:11
  • I edited my answer to mention that you can get the same kind of highlighting with Isearch+. – Drew Dec 5 '17 at 5:16
2

If you use Isearch+, or if you use Icicles, then you can get this kind of regexp-group highlighting when you use Isearch or Icicles search, respectively.

For example, this screenshot shows highlighting for this input regexp:

(\([-a-z*]+\) *\((\(([-a-z]+ *\([^)]*\))\))\).*. It shows 4 levels of subgroup highlighting plus highlighting (level 0) of the full regexp match. (Up to 8 highlighting levels are possible.)

enter image description here

Whether to highlight regexp subgroups is controlled by option isearchp-highlight-regexp-group-levels-flag in Isearch and by option icicle-search-highlight-context-levels-flag in Icicles search.

In Isearch you can toggle regexp-group highlighting anytime while searching by hitting M-s h R. (In Isearch+ while searching, prefix key M-s h controls various kinds of highlighting.) Only the current search hit shows regexp-group highlighting, but the other search hits have their odd and even regexp groups highlighted differently, to easily distinguish them.


isearchp-highlight-regexp-group-levels-flag is a variable defined in isearch+.el.

Its value is t

Documentation:

Non-nil means highlight 1-8 regexp group levels, within search hit.

You can toggle this value using M-s h R during Isearch.

You can customize this variable.


icicle-search-highlight-context-levels-flag is a variable defined in icicles-opt.el.

Its value is t

Documentation:

Non-nil means highlight up to 8 context levels, within the search context.

Level highlighting is done only when this is non-nil and a subgroup is not used as the search context, that is, the context corresponds to the entire search regexp.

Remember that you can use multi-command icicle-toggle-option' anytime (**M-i M-i'** during completion) to toggle an option value.

You can customize this variable.

The faces used for regexp-group highlighting in Icicles search are icicle-search-context-level-1 through icicle-search-context-level-8. In Isearch they are faces isearchp-regexp-level-1 through isearchp-regexp-level-8.

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.