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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 20622 invoked from network); 14 Sep 2022 18:58:01 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 14 Sep 2022 18:58:01 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1663181881; b=exc/JfB6IsCOHIE+l0wRhbx443lOBuB5FHRANnO38a+t2NqspZ2gcVrKF0ocYgOZzZNpz0UMg7 RsEHhzaAkAu6ID5C79XcnglPZRCMHLfku7mYuU3juoKjPHaxhuk289TTx6SKkdNvCj1yBNlkGb hR2kwgsokIEwGwR/oiCVJYRHnrIaL/IKgHv9AGdLiqNKbGKLWzIDEWQBj38IZ8FZ4JWnAa3hPE nomio+9qEVaMckDaGKbbieaXS7+TbbM2x9qNX3SOpKieP6r3uqAI8aLGMXi354awHga+rSrYS8 Hur0e5XIEQ0DVp7AXslqH/jOR4fQEq+ObuSkFg+/NDhVMQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f49.google.com) smtp.remote-ip=209.85.208.49; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1663181881; bh=GcxbmEHN0TsQTNeMh/voq9i3ljplTEBZOQDsSFKn5+4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=YYAcGZ+wZcBH04l3WIBzAklcS9W+SYAUScpBm2m9C97ulSlft5NIwfoCiSavqkGeMz3T698Gjb yUpl3lgywumixOHcyB7uEgXQrUAiO4rMA4qRK1sAviXUO0QMPrYiA1H86oZBnFmOMLbUwPws8D g9EdmFDGYuRfaJH+1yCrMyWvS9OEIoIYn38MB1G7oQv9mvMRNHf9mBE1Gb0H/Gwuz3IwEpfZiG cevqyVc/3tixgabTU/lt/1g8FcdSxlHFL8KF0D0nS+Kvm3eLifNoqJXHQa9dC0zQN8XtPkW5td xz6GPnFApIQLmx1ZrjZC7Mgdt8XbD/CNhMbUCsYXL6coig==; 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Dzxr3K9BViFCdX+sLTrwRROeXj35osZVppcfrY9hLmc=; b=o7wcMV6BkyHHcvedYN8ELcv9B3 LZ5PFIRxCfzVkNP2zAqCBJuUfa9CtDHxtJDdtmLoxBoEavtgM7eAY4fKZ76//5e0dmV96ahKerdhK 204nM0QasiqD+E0pyvcO8bseOR1dLrOUxHPw32b96k+AaHSjgWY16teMEmZdCfqNwjVXCSCmnIJja Nkt6glxZCY0w5AKfYTCMqiBrfQgrsXY+XMzwdNyh4qrcRpOh5ufBugVNFZkHJtwcxguXEkHPu0d9H KIWnTiCwDo9X6m7hQrHsleukHB1cFvFptUOZW3cnfHj4FzIGc4QZ39buMANI2/XqMzk0kTCC8kVPt qQVzDXIw==; Received: from authenticated user by zero.zsh.org with local id 1oYXaC-000OdY-FZ; Wed, 14 Sep 2022 18:58:00 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f49.google.com) smtp.remote-ip=209.85.208.49; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f49.google.com ([209.85.208.49]:43993) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oYXZD-000NyK-Ca; Wed, 14 Sep 2022 18:57:00 +0000 Received: by mail-ed1-f49.google.com with SMTP id y8so16740913edc.10 for ; Wed, 14 Sep 2022 11:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=Dzxr3K9BViFCdX+sLTrwRROeXj35osZVppcfrY9hLmc=; b=4jLZ+wu6IAW4XId8yuImjDOf/nyTu03yJZPP9i743jbi45mKOJLrmCZazxrVz4BAfg juzdhNJukfx3MWNxuCo8dogid/YNwLngRbUpWW79RGy8hu7lWUPPcTFk8F8Tkb+faSj3 moPvk4RJrUQj1L2GFS9iB8W2YVNTGXjCj9xblbOL9GTXkmJgUzC+49ETvneHtu1ZjM9R 3D9MSz6yhVOOuVUgogM+H+Jbd1/X4JKk/hTNCAkrYsPyAvbXf4cqoDpubrmWEIScQwv0 e9dn/SCXFKLE4OTZmqyamv8+P6fyOOVyatToAxlHPDYUZFSXGbP8cCP+enCkCY3g1fOW eojQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=Dzxr3K9BViFCdX+sLTrwRROeXj35osZVppcfrY9hLmc=; b=QQTx01CUGAzo+hAoVeYThpXzsqKZPouo+amMEquMD96uDvoykqcR1W3WwuZIfT4EQ+ 5iU9vA33pqYQw4RxN4G1rE5TE4p/uoBkf42IC/iI3gM9NIKyXhC1u/Ln7jj0AleY96XR U+l3c9V9e1cSiDLgPrBZMnf0FTekz2yDnNuLReabFWOwDGSydjUeeOSLoMIzy0igolMt 2EOBAgLP63DgLBIF66YX1XYMU3aOZsseYSMVRR4MTsUW8O2PI48y7UoNBSXTit4H7Z5c n5uXPAJOBrjf/ruaNxWHeKkexMRG56RJOYOxH4kXNXviwt0d2aKdRijUBiuPuU4/McY6 Bg5w== X-Gm-Message-State: ACgBeo1P+6Xo52CgoEtZQKOFCF+EXQ+vHohPhh9HgkWRVhW3iTJ1afwL VvbDrfB/fOn3Ue9MPAq37lhw61flk4Df7fMU6LezCA== X-Google-Smtp-Source: AA6agR4AXNUvxbpZheRxD39J2xWWQma2mim75Zt3ij8Qg0n4WHgxKCJlKBHuBfI9bqsrBj9vjwWFna1Gj5/zm62L6Fc= X-Received: by 2002:a05:6402:50d4:b0:451:bf26:8c41 with SMTP id h20-20020a05640250d400b00451bf268c41mr14061772edb.219.1663181819024; Wed, 14 Sep 2022 11:56:59 -0700 (PDT) MIME-Version: 1.0 References: <4844b850-2ca6-4c90-95ae-aae00dc339cf@www.fastmail.com> In-Reply-To: From: Bart Schaefer Date: Wed, 14 Sep 2022 11:56:47 -0700 Message-ID: Subject: Re: Substitute the last match of a pattern during parameters expansion. To: Michele Venturi Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 28071 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 Tue, Sep 13, 2022 at 8:20 PM Michele Venturi wrote: > > Plus you seem quite good at non trivial tasks if you can > write that monstrousity... Do you know instead what IS trivial? Counting, to know how many matches there are. Definitely keep using that approach, and see how much help it gets you in future. > There are many examples of supporting negative index, > so I still don't see a reason why it is so difficult to do it... For benefit of other readers ... Forward indexing walks over the string once, replacing each occurrence of a match as it finds it. To implement negative indexing, it is necessary to walk once to the end of the string to count the number of occurrences, while "remembering" where each one appears, and then backtrack to the position of the Nth-from-last match and replace just that one. Those who think this is both easy and worthwhile to implement will find the code in Src/glob.c in the function igetmatch(). Be sure to trace the call chain all the way back to Src/subst.c to be sure you're not violating any other constraints.