Skip to content

Commit caeca0b

Browse files
jnooreedanielshahaf
authored andcommitted
docs: regexp: Document the platform dependency
Patch by Nuri Jung; extension to cover PCRE by me. See #747. Fixes #747.
1 parent 56b4433 commit caeca0b

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

docs/highlighters/regexp.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,44 @@ To use this highlighter, associate regular expressions with styles in the
1212

1313
```zsh
1414
typeset -A ZSH_HIGHLIGHT_REGEXP
15-
ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold)
15+
ZSH_HIGHLIGHT_REGEXP+=('^rm .*' fg=red,bold)
1616
```
1717

18-
This will highlight "sudo" only as a complete word, i.e., "sudo cmd", but not
19-
"sudoedit"
18+
This will highlight lines that start with a call to the `rm` command.
19+
20+
The regular expressions flavour used is [PCRE][pcresyntax] when the
21+
`RE_MATCH_PCRE` option is set and POSIX Extended Regular Expressions (ERE),
22+
as implemented by the platform's C library, otherwise. For details on the
23+
latter, see [the `zsh/regex` module's documentation][MAN_ZSH_REGEX] and the
24+
`regcomp(3)` and `re_format(7)` manual pages on your system.
25+
26+
For instance, to highlight `sudo` only as a complete word, i.e., `sudo cmd`,
27+
but not `sudoedit`, one might use:
28+
29+
* When the `RE_MATCH_PCRE` is set:
30+
31+
```zsh
32+
typeset -A ZSH_HIGHLIGHT_REGEXP
33+
ZSH_HIGHLIGHT_REGEXP+=('\bsudo\b' fg=123,bold)
34+
```
35+
36+
* When the `RE_MATCH_PCRE` is unset, on platforms with GNU `libc` (e.g., many GNU/Linux distributions):
37+
38+
```zsh
39+
typeset -A ZSH_HIGHLIGHT_REGEXP
40+
ZSH_HIGHLIGHT_REGEXP+=('\<sudo\>' fg=123,bold)
41+
```
42+
43+
* When the `RE_MATCH_PCRE` is unset, on BSD-based platforms (e.g., macOS):
44+
45+
```zsh
46+
typeset -A ZSH_HIGHLIGHT_REGEXP
47+
ZSH_HIGHLIGHT_REGEXP+=('[[:<:]]sudo[[:>:]]' fg=123,bold)
48+
```
49+
50+
Note, however, that PCRE and POSIX ERE have a large common subset:
51+
for instance, the regular expressions `[abc]`, `a*`, and `(a|b)` have the same
52+
meaning in both flavours.
2053

2154
The syntax for values is the same as the syntax of "types of highlighting" of
2255
the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
@@ -28,3 +61,5 @@ in [the `zshmisc(1)` manual page][zshmisc-Conditional-Expressions]
2861
[zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting
2962
[perlretut]: http://perldoc.perl.org/perlretut.html
3063
[zshmisc-Conditional-Expressions]: http://zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html#Conditional-Expressions
64+
[MAN_ZSH_REGEX]: https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-zsh_002fregex-Module
65+
[pcresyntax]: https://www.pcre.org/original/doc/html/pcresyntax.html

0 commit comments

Comments
 (0)