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

Re: coloring substitution seems to eat next line.




On 2022-11-13 07:09, Ray Andrews wrote:
Roman:

            cc=( ${(M)cc:#*$~zsh_case${filter}*} )

I've been applying that in some other functions but I need a variation that will erase non-matching lines but leave them as blanks so that array indexes do not change.  Reason being that a subsequent merge with another array will happen and indexes must mesh.  I'm doing it right now by using a dummy string as replacement for a non-match and then combining the arrays and then deleting the dummies but that's obviously clumsy.

Stéphane Chazelas over at StackExchange offers this:

        cc=( "${cc[@]/#%^*$~zsh_case${filter}*}" )

... and it seems to do exactly what I want.  I understand the negation and the way the '[@]' and the outer quotes protect the length of the array, now I just need to understand the '#%' anchors -- but they are essential.







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