From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10313 invoked by alias); 16 Oct 2015 12:36:01 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20774 Received: (qmail 16692 invoked from network); 16 Oct 2015 12:36:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=XtIZGyRbWMsgWxx9r5ce6vD3JnorrH7uuxvRGs/YxH4=; b=d58ebAJKhRdx7HBn3at+Hb15kjmn6kijf/Eber+5Q+mnDJcgdQVO0OpVTFMRW2ZENB Sim/oXFBD24iGGirBk0uk8cjiqK4m2YBe89DGUTSS3Ux9dg+NtimH5wyJROjacumP62B ZoilXxG/egDQlaEXxHsdhVAKpVQd9ucYXP9Zou/eMqEWn3/jXuHGA9TTMNFuLSvMIb5a adhoTyphRX/Q4mqMUT8cQ0aiqxKqMqdIC5ubIHDDUMcXRQB5vCaJmqiahsYDqdH1N4hW +5N2nAWhgdgEksTfEBoHC4AYk53tEsuoB7ETiDVyfrDlgJloM8830afPT12K4pS16pO8 RDUQ== X-Gm-Message-State: ALoCoQknrtWUjuPfVr8QhHcLCPbQxp2GV38viIU+NI32eXEDVCiaDZyFyTVELNLytVtepfJ/zZ1v X-Received: by 10.60.35.194 with SMTP id k2mr9064052oej.67.1444998957103; Fri, 16 Oct 2015 05:35:57 -0700 (PDT) From: Bart Schaefer Message-Id: <151016053555.ZM31602@torch.brasslantern.com> Date: Fri, 16 Oct 2015 05:35:55 -0700 In-Reply-To: <56208CF8.1070906@eastlink.ca> Comments: In reply to Ray Andrews "Re: backreferences" (Oct 15, 10:36pm) References: <561FF039.9020202@eastlink.ca> <151015161602.ZM30622@torch.brasslantern.com> <56204FD3.9040500@eastlink.ca> <151015193032.ZM30783@torch.brasslantern.com> <56208CF8.1070906@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: backreferences MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 15, 10:36pm, Ray Andrews wrote: } } > if [[ "$sstring" = (#b)((^(edcba))*)(edcba)(*) ]] } > } > There are 5 sets of parens, and you care about $match[1], $match[4], } > and $match[5]. $match[2] is the prefix of $match[1] that was not } > consumed by the middle *, and $match[3] is an empty substring of } > $match[2] (because it was excluded from matching). Count off the } > open parens left to right to see this. } At the moment I'm quite confounded. So '(b#)' is looking at every set } of '()' even } when nested and even when 'doing something else'? Yes. } > In fact you don't even need the middle * because (^edcba) will eat } > an arbitrarily long string as long as it is not literally "edcba". } Well, that's the original question. As noted in my follow-up mail, what I wrote there is actually not right; the part after "because" is correct, but the part about not needing the middle * is wrong, because (^edcba) matches xxxxedcbaxxxx just fine, and I assume you don't want that. } > So you can reduce this to } > } > if [[ "$sstring" = (#b)(^edcba)(edcba)(*) ]] This needs to be (#b)(^edcba*)(edcba)(*) } God knows. But your simplified command works fine too, and I'll } take it on faith. I've never seen any sort of 'any number of characters' } sort of thing look other than: } [....]* No, now you're confusing grep-style regular expressions with zsh patterns. EGREP ZSH . ? .* * or ?# .+ ?## .? (?|) [xyz] [xyz] [xyz]* [xyz]# There's a lot more but those are the most important bits. } ... so you can see where I'd go astray there. Ok, so } ^(edcba) } is individual character matches and } (^edcba) } is anything up to "edcba" No. [^edcba] is individual character matches and (^edcba) is anything other than the literal string edcba, including longer strings that have edcba as a substring. Negated patterns are really tricky.