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

Re: non-greedy match



On Thu, Nov 10, 2022 at 5:19 PM Pier Paolo Grassi <pierpaolog@xxxxxxxxx> wrote:
>
> Hello, is it possibile to force non greedy matching for globbing expressions?

Only within a parameter expansion.  So something like

str='{{{a}}}{{{b}}}'
hack=$str
tmp=
unset match # or local -a match if in a function
while hack=${(S)hack/(#b)(*)'{{{'(*)'}}}'(*)} && [[ -n $match ]]
do
  vared -p "$match[2]: "  tmp
  str=$match[1]$tmp$match[3]
  hack=$str$hack
  unset match
done
echo $str


> I use this code to replace interactively some template labels:
>
> str='{{{a}}}{{{b}}}'
> tmp=
> while [[ $str == (#b)(*)'{{{'(*)'}}}'(*) ]]
> do
>   vared -p "$match[2]: "  tmp
>   str=$match[1]$tmp$match[3]
> done
> echo $str
>
> I would like for them to be presented in the order they occur in $str, I get them backward instead
>
> thanks
>
> Pier Paolo Grassi




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