From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14017 invoked from network); 24 Apr 2004 08:09:33 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 24 Apr 2004 08:09:33 -0000 Received: (qmail 26648 invoked by alias); 24 Apr 2004 08:09:03 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7404 Received: (qmail 26625 invoked from network); 24 Apr 2004 08:09:02 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 24 Apr 2004 08:09:02 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 24 Apr 2004 8:9:2 -0000 Received: (qmail 11135 invoked from network); 24 Apr 2004 08:09:02 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 24 Apr 2004 08:09:01 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id i3O88td31765; Sat, 24 Apr 2004 10:08:55 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1BHI23-0000Up-00>; Sat, 24 Apr 2004 09:57:03 +0200 Date: Sat, 24 Apr 2004 09:57:03 +0200 From: DervishD To: Bart Schaefer Cc: Zsh Users Subject: Re: Expanding when matching Message-ID: <20040424075703.GB1881@DervishD> Mail-Followup-To: Bart Schaefer , Zsh Users References: <20040423211540.GA1821@DervishD> <1040424041414.ZM17671@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1040424041414.ZM17671@candle.brasslantern.com> User-Agent: Mutt/1.4.2.1i Organization: Pleyades X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-1.5 required=6.0 tests=BAYES_01 autolearn=no version=2.63 X-Spam-Hits: -1.5 Hi Bart :) * Bart Schaefer dixit: > } $ print ${testvar/#This*%/Replaced} > } This is my test var > } The example doesn't make much sense, but it illustrates what I > } mean. What I'm doing wrong? What am I not understanding? > I know Wayne has already answered, but: > The # and % tokens in ${var/pat/rep} are not analogous to regex ^ and $. > Rather, they're analogous to ${var#pat} and ${var%pat}. Does that help? It helps a lot, thanks :) As I told Wayne, I was doing a bad reading of the manual, which clearly states that both symbols MUST BE AT THE BEGINNING of the pattern... > For the analogs of ^ and $, you need (#s) and (#e) [and extendedglob]. > $ print ${testvar/(#s)This*var(#e)/Replaced} And this confused me the most, because I didn't know why the heck zsh needed (#s) and (#e) having '#' and '%', which didn't need extendedglob to be set. Now ALL makes sense. Thanks for the help :) > } replace some numbers in one text that should be consecutive but are > } not, and they are interspersed with arbitrary text. What I know about > } them is that they are alone in a line, so they match certain regex, > setopt extendedglob > c=0; while read line; do print ${${line#<->(#e)}:-$[++c]}; done > (Replacing <-> with your pattern.) I tried something similar (and completely wrong): counter=0; for number in {1..100} do print ${number/(*0*)/Hit a ten! ${match[1]:-$((counter++))}} done Which obviously doesn't work neither, because the expansion takes place no matter if a match occured or not. Your solution works perfectly :) And I can use backrefs with it :)) Thanks a lot, Bart :) Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/