From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28961 invoked from network); 12 Sep 2022 06:02:39 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Sep 2022 06:02:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Subject:Cc:To:From:Date:References:In-Reply-To:Message-Id: Mime-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=06pqwYJy0refhLRx+ZzMbdcPKchcqtuIC4wgFC1vhFc=; b=AqzR6h73hCnYpvK6iCuxyKM9Ox JUHEiQepuLY1QbiMOmt65hB5jYrPmUZuchudvyDtxxwl5ALeDwyEH47N0cdW6E1pySi/SGLDyFLtK NSU4MswuaYv4HqDeI2V2thVjvWCOfZClLTwWw35YUyyO+1kaOIGfPSN7+ZLwKBmr7G0Fl08YSmEd4 5xKGBPfrjK9/AlVkTvCRP88kdMNpeOYvGF6MpSKFPhAu4bALCExL7ZepdCJzEVplFHeiTd/S/tSnC qF+82qsJJfAVCX9/TXyLqjCR2Hq4y4mhX6BDWiQ35h3EZ/ZJqO234KFVnJiRw2VsXgqfu+HW6wLmL ZAs0chyw==; Received: from authenticated user by zero.zsh.org with local id 1oXcWk-000Lrj-Ie; Mon, 12 Sep 2022 06:02:38 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1oXcVp-000L7d-6D; Mon, 12 Sep 2022 06:01:42 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 74CDF27C0054; Mon, 12 Sep 2022 02:01:39 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Mon, 12 Sep 2022 02:01:39 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeduuddguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvfevufgtgf esthhqredtreerjeenucfhrhhomhepnfgrfihrvghntggvpgggvghljoiiqhhuvgiiuceo lhgrrhhrhihvseiishhhrdhorhhgqeenucggtffrrghtthgvrhhnpedttefhveegtedtgf eufedutdehfeejheffffduvdeukefhteffvddthfevgeeggeenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihvhdomhgvshhmthhprg huthhhphgvrhhsohhnrghlihhthidqudduhedukeejjedtgedqudduledvjeefkeehqdhl rghrrhihvheppeiishhhrdhorhhgsehfrghsthhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: iaa214773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4E76A31A0062; Mon, 12 Sep 2022 02:01:39 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-927-gf4c98c8499-fm-20220826.002-gf4c98c84 Mime-Version: 1.0 Message-Id: In-Reply-To: References: Date: Mon, 12 Sep 2022 02:01:13 -0400 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: "Michele Venturi" Cc: zsh-users@zsh.org Subject: Re: Substitute the last match of a pattern during parameters expansion. Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Seq: 28062 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Mon, Sep 12, 2022, at 12:20 AM, Michele Venturi wrote: > Hello, I have a problem, can you help me? > I would like to substitute the last match of > a pattern during parameters expansion=E2=80=A6 > The string aXbXc should become aXbYc; > I have not found a direct and general way > of doing it, but there are some solutions=E2=80=A6 > > The problem is that they are cumbersome: > ${str%X*}Y${str##*X} is too convoluted for > such a simple operation in my opinion, no? Lots of tasks could be reasonably described as "simple". The shell cannot provide succinct solutions to all of them. > So is there an easier way to get the desired > result Here's one approach. % foo=3DaXbXcXdXe =20 % print ${(*)foo/(#b)(*)X/$match[1]Y} aXbXcXdYe > 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=E2=80=A6 There is already a '%' flag. I do not think this merits a new one. > Obviously adding negative indexes support > to the I flag would be very good but verbose > for the most common use case of that, right? Extending the 'I' flag in this way would be ideal, if possible. --=20 vq