zsh-users
 help / color / mirror / code / Atom feed
* Substitute the last match of a pattern during parameters expansion.
@ 2022-09-12  4:20 Michele Venturi
  2022-09-12  6:01 ` Lawrence Velázquez
  0 siblings, 1 reply; 24+ messages in thread
From: Michele Venturi @ 2022-09-12  4:20 UTC (permalink / raw)
  To: zsh-users

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

Hello, I have a problem, can you help me?
I would like to substitute the last match of
a pattern during parameters expansion…
The string aXbXc should become aXbYc;
I have not found a direct and general way
of doing it, but there are some solutions…

The problem is that they are cumbersome:
${str%X*}Y${str##*X} is too convoluted for
such a simple operation in my opinion, no?

Hard-coding a number like in ${(I:2:)str/X/Y}
is usually not a good idea, don’t you agree?
Other possibilities have similar down sides.

So is there an easier way to get the desired
result or should it be added to the software
and how complicated would be to change it?

I would suggest a new flag like % or $ for it.
I wonder if the syntax ${(%)str/X/Y} is going
to conflict with other functionalities of ZSH…

Obviously adding negative indexes support
to the I flag would be very good but verbose
for the most common use case of that, right?

What do you think about this whole matter?
What should I learn to find out how to do it?
Your thoughts on the topic are appreciated…


<https://about.me/dardo82?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api&utm_content=thumb>
Michele Venturi
about.me/dardo82
<https://about.me/dardo82?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api&utm_content=thumb>

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

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

end of thread, other threads:[~2022-09-16  9:09 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-12  4:20 Substitute the last match of a pattern during parameters expansion Michele Venturi
2022-09-12  6:01 ` Lawrence Velázquez
2022-09-13  4:19   ` Michele Venturi
2022-09-13  6:06     ` Lawrence Velázquez
2022-09-13 23:11       ` Bart Schaefer
2022-09-14  3:20         ` Michele Venturi
2022-09-14 18:56           ` Bart Schaefer
2022-09-14 20:06             ` Ray Andrews
2022-09-14 21:59             ` Michele Venturi
2022-09-14 22:04               ` Bart Schaefer
2022-09-14 22:20                 ` Michele Venturi
2022-09-15  0:00                   ` Alex Satrapa
2022-09-15  0:29               ` Lawrence Velázquez
2022-09-15  1:45                 ` Michele Venturi
2022-09-15 12:01                   ` Roman Perepelitsa
2022-09-15 23:29                     ` Michele Venturi
2022-09-16  6:37                       ` Roman Perepelitsa
2022-09-16  7:52                         ` Michele Venturi
2022-09-16  7:57                           ` Roman Perepelitsa
2022-09-16  8:19                             ` Michele Venturi
2022-09-16  8:22                               ` Roman Perepelitsa
2022-09-16  8:33                                 ` Michele Venturi
2022-09-16  8:36                                   ` Roman Perepelitsa
2022-09-16  9:08                                     ` Michele Venturi

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).