zsh-users
 help / color / mirror / code / Atom feed
From: Michele Venturi <dardo82@gmail.com>
To: zsh-users@zsh.org
Subject: Substitute the last match of a pattern during parameters expansion.
Date: Mon, 12 Sep 2022 06:20:35 +0200	[thread overview]
Message-ID: <CA+Ds4NsnE6HvV_Kf59KO5_=8Jb4STxwAzL8x+EUq1aiQdB91ZA@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2022-09-12  4:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12  4:20 Michele Venturi [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+Ds4NsnE6HvV_Kf59KO5_=8Jb4STxwAzL8x+EUq1aiQdB91ZA@mail.gmail.com' \
    --to=dardo82@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).