From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17867 invoked by alias); 16 Oct 2015 16:38:02 -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: 20775 Received: (qmail 20094 invoked from network); 16 Oct 2015 16:37:58 -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-Authority-Analysis: v=2.1 cv=X+5rdgje c=1 sm=1 tr=0 a=vsFYQC4/11PqlKifmEOq9w==:117 a=vsFYQC4/11PqlKifmEOq9w==:17 a=N659UExz7-8A:10 a=IkP4GcmaYm8TwCc-GksA:9 a=pILNOxqGKmIA:10 Message-id: <562127E4.2050804@eastlink.ca> Date: Fri, 16 Oct 2015 09:37:56 -0700 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: backreferences References: <561FF039.9020202@eastlink.ca> <151015161602.ZM30622@torch.brasslantern.com> <56204FD3.9040500@eastlink.ca> <151015193032.ZM30783@torch.brasslantern.com> <56208CF8.1070906@eastlink.ca> <151016053555.ZM31602@torch.brasslantern.com> In-reply-to: <151016053555.ZM31602@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 10/16/2015 05:35 AM, Bart Schaefer wrote: > } when nested and even when 'doing something else'? > > Yes. Ok, good to know. I've only been using backreferences since two days ago and up till now it's seemed that you had to add parentheses to create the reference and existing parentheses only had their existing syntax. I suppose this means that when you do have existing parentheses you'll get a 'match' whether you want one or not but so what, just ignore it. Yup, that's best. > ... but the part about not needing the > middle * is wrong, because (^edcba) matches xxxxedcbaxxxx just fine, and > I assume you don't want that. test2 () { match= sstring="abcdeedcbaabcde" # Bart doesn't like: #if [[ "$sstring" = (#b)([(^(edcba))]*)(edcba)(*) ]]; # Bart likes: if [[ "$sstring" = (#b)(^edcba)(edcba)(*) ]]; then echo "\nIt's a poyfect match\n" fi echo "one $match[1]" echo "two $match[2]" echo "three $match[3]" echo "four $match[4]" echo "five $match[5]" } It's a poyfect match one abcde two edcba three abcde four five ... match[1] seems to agree with your previous interpretation, no? > This needs to be (#b)(^edcba*)(edcba)(*) That produces identical output as well, so what's the diff? Probably one of those things that blows up in your face one day ... > } 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. ... which is what I meant to say. > EGREP ZSH > . ? > .* * or ?# > .+ ?## > .? (?|) > [xyz] [xyz] > [xyz]* [xyz]# > > There's a lot more but those are the most important bits. A table like that is worth tattooing onto one's arm. Seriously once a fella has learned a bit of regex it becomes burnt into the brain, and it's an act of deliberation to use the other syntax. It sorta makes it worse that they are similar :( Is a complete table available somewhere? > } ... 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, Ok, got it. A mortal's guide to this stuff would sure be useful. All the docs tend to dive right in to the deep end and immediately start explaining all the possible obscure permutations when KSH_GLOB is set and it's not leap year but it IS a Friday. Such control! But we start with the basics. > including longer strings that have > edcba as a substring. Negated patterns are really tricky. Na.