zsh-users
 help / color / mirror / code / Atom feed
* non-greedy match
@ 2022-11-11  1:18 Pier Paolo Grassi
  2022-11-11  1:41 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Pier Paolo Grassi @ 2022-11-11  1:18 UTC (permalink / raw)
  To: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Hello, is it possibile to force non greedy matching for globbing
expressions?
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

[-- Attachment #2: Type: text/html, Size: 816 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: non-greedy match
  2022-11-11  1:18 non-greedy match Pier Paolo Grassi
@ 2022-11-11  1:41 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-11-11  1:41 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Thu, Nov 10, 2022 at 5:19 PM Pier Paolo Grassi <pierpaolog@gmail.com> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-11  1:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-11  1:18 non-greedy match Pier Paolo Grassi
2022-11-11  1:41 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).