* no wildcards/anchors allowed in pattern? ${f:s/pattern/_s&}
@ 2022-09-08 11:56 zzapper
[not found] ` <826663136.300323.1662640732618@mail.virginmedia.com>
0 siblings, 1 reply; 3+ messages in thread
From: zzapper @ 2022-09-08 11:56 UTC (permalink / raw)
To: Zsh-Users List
Hi
This works for me and allows me to use memory '&' but I'm frustrated
that I don't seem to be able to use anchors / wildcards etc in the pattern
f=dog.png ;echo $f '->' ${f:s/./_s&}
dog.png -> dog_s.png
the alternative syntax allows pattern to be a regexp but has no regexp
memory
f=dog.png.png ;echo $f '->' ${f/%.png/_s.png}
dog.png.png -> dog.png_s.png
(be delighted to be told I'm wrong!)
zzapper
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: no wildcards/anchors allowed in pattern? ${f:s/pattern/_s&}
[not found] ` <826663136.300323.1662640732618@mail.virginmedia.com>
@ 2022-09-08 13:16 ` Peter Stephenson
2022-09-08 13:57 ` zzapper
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2022-09-08 13:16 UTC (permalink / raw)
To: zsh-user
Sorry, didn't go to the list, agian...
> On 08/09/2022 12:56 zzapper <zsh@rayninfo.co.uk> wrote:
> This works for me and allows me to use memory '&' but I'm frustrated
> that I don't seem to be able to use anchors / wildcards etc in the pattern
>
> f=dog.png ;echo $f '->' ${f:s/./_s&}
> dog.png -> dog_s.png
>
> the alternative syntax allows pattern to be a regexp but has no regexp
> memory
>
>
> f=dog.png.png ;echo $f '->' ${f/%.png/_s.png}
> dog.png.png -> dog.png_s.png
The pattern expansion case has this syntax:
f=stuff.png
print ${foo/%(#m).png/_$MATCH}
stuff_.png
Look up the "m" globbing flag.
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: no wildcards/anchors allowed in pattern? ${f:s/pattern/_s&}
2022-09-08 13:16 ` Peter Stephenson
@ 2022-09-08 13:57 ` zzapper
0 siblings, 0 replies; 3+ messages in thread
From: zzapper @ 2022-09-08 13:57 UTC (permalink / raw)
To: zsh-users
On 08/09/2022 14:16, Peter Stephenson wrote:
> Sorry, didn't go to the list, agian...
>
>> On 08/09/2022 12:56 zzapper <zsh@rayninfo.co.uk> wrote:
>> This works for me and allows me to use memory '&' but I'm frustrated
>> that I don't seem to be able to use anchors / wildcards etc in the pattern
>>
>> f=dog.png ;echo $f '->' ${f:s/./_s&}
>> dog.png -> dog_s.png
>>
>> the alternative syntax allows pattern to be a regexp but has no regexp
>> memory
>>
>>
>> f=dog.png.png ;echo $f '->' ${f/%.png/_s.png}
>> dog.png.png -> dog.png_s.png
> The pattern expansion case has this syntax:
>
> f=stuff.png
> print ${foo/%(#m).png/_$MATCH}
> stuff_.png
>
> Look up the "m" globbing flag.
>
> pws
>
thanks this does what I require accepts *.{jpg,jpeg,png,gif}
f=stuff.jpg; print ${f/%(#m).[pjg][npi]e#[gf]/_s$MATCH}
stuff_s.jpg
zzapper
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-08 13:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-08 11:56 no wildcards/anchors allowed in pattern? ${f:s/pattern/_s&} zzapper
[not found] ` <826663136.300323.1662640732618@mail.virginmedia.com>
2022-09-08 13:16 ` Peter Stephenson
2022-09-08 13:57 ` zzapper
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).