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?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityIs 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?
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.)
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 inisearch+.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 inicicles-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
.