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

Re: no wildcards/anchors allowed in pattern? ${f:s/pattern/_s&}




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@xxxxxxxxxxxxxx> 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






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