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

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



On Nov 1, 11:53pm, Sebastian Gniazdowski wrote:
} Subject: Re: Match to the end of string when using (S) flag
}
} On Tue, Nov 1, 2016, at 02:23 PM, Bart Schaefer wrote:
} > You can do this with just a counter, you don't need a math function:
} > 
} >   i=$#region_highlight
} >   : ${text//(#mi)(${~colsearch_pattern})/
} >       ${region_highlight[++i]=$((offset + MBEGIN))}
} >       ${region_highlight[++i]=$((offset + MEND))}
} >       ${region_highlight[++i]=${__hsmw_hl_color}}}
} 
} Couldn't get this to work, although $i before and after differs much,
} however looked at contents and there are lines like:
} 
} 193 -1 none
} -1 -1 none
} -1 -1 bg=17
} -1 -1 none
} 
} so something doesn't append well.

Here was my dummy test case:

setopt extendedglob
text="123 Abc 456 Ade 789 Afg 0"
colsearch_pattern="A??"
() {
  local -ah region_highlight=( 1 1 xy=z )
  local i=$#region_highlight offset=3 __hsmw_hl_color="pd=q"
  : ${text//(#mi)${~colsearch_pattern}/
      ${region_highlight[++i]=$((offset + MBEGIN))}
      ${region_highlight[++i]=$((offset + MEND))}
      ${region_highlight[++i]=${__hsmw_hl_color}}}
  print -r -- $region_highlight
}

With the result

1 1 xy=z 8 10 pd=q 16 18 pd=q 24 26 pd=q

(note offset=3 so 8 10 means $text[5,7] which is Abc, etc.)



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