Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

MBEGIN, MEND in #m when pattern has "|"



Hello,
below is a code that uses indexes set by (#m) or (#b). Turns out the
indexes are set only when using (#b). For (#m) they are set when there
is no "|" in the pattern. Why?

Output is:
==========================

Text is: vim ~/.zshrc s, searching for: vim|s
|-1 0 fg=red,bold|
 ~/.z|-1 0 fg=red,bold|
hrc |-1 0 fg=red,bold|

Text is: vim ~/.zshrc s, searching for: vim|s
|0 3 fg=red,bold|
|8 9 fg=red,bold|
|13 14 fg=red,bold|

Code:
==========================

#!/usr/bin/env zsh

nl=$'\n'
text="vim ~/.zshrc s"
colsearch_pattern="vim|s"

harray=( "${(f)${text//(#mi)${~colsearch_pattern}/|$(( MBEGIN - 1 ))
$(( MEND )) fg=red,bold|$nl}%$nl*}" )
echo "Text is: $text, searching for: $colsearch_pattern"
print -rl -- "${harray[@]}"

print

harray=( "${(f)${(S)text//*(#bi)(${~colsearch_pattern})/|$(( mbegin[1]
- 1 )) $(( mend[1] )) fg=red,bold|$nl}%$nl*}" )
echo "Text is: $text, searching for: $colsearch_pattern"
print -rl -- "${harray[@]}"



Messages sorted by: Reverse Date, Date, Thread, Author