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

Match to the end of string when using (S) flag



Hello,
I do:

% a="AXbcAXdeAXfg"; echo ${(S)a//*(AX)/x}
xxxfg

to generate region_highlight entries. As it can be seen, there is
trailing data, which Zsh converts to "-1 -1 none". I would want to
generate clean region_highlight entries. Came up with this:

% a="AXbcAXdeAXfg"; echo ${a//(*(AX)*(#e)~*AX*AX*|*AX~*AX*AX*)/x}
xxx

Surprisingly, it is faster (e.g. 170ms vs 780 ms) than (S) flag IF AX is
not a complex pattern like AX|BX. Then it is slow, so I cannot use this.
Also, I'm not sure if it isn't possible that exclusion ~*AX*AX* will
lead to acceptance of X*AX*, but this doesn't seem to occur.

Is there way out of this? Thought about using (R) flag out of the set of
BEMNR "... include in result" flags, but I cannot provoke anything
distinct with them.

PS. The actual region_highlight generating code is:

region_highlight+=( "${(f)${(S)text//*(#bi)(${~colsearch_pattern})/$((
offset + mbegin[1] - 1 )) $(( offset + mend[1] ))
${__hsmw_hl_color}${nl}}%$nl*}" )

offset is length of a preamble (all for $POSTDISPLAY) that is not
colored.

-- 
  Sebastian Gniazdowski
  psprint@xxxxxxxxxxxx



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