From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3131 invoked from network); 11 Oct 2006 13:02:44 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.6 (2006-10-03) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.6 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Oct 2006 13:02:44 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 31833 invoked from network); 11 Oct 2006 13:02:36 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Oct 2006 13:02:36 -0000 Received: (qmail 13662 invoked by alias); 11 Oct 2006 13:02:26 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10825 Received: (qmail 13652 invoked from network); 11 Oct 2006 13:02:24 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 Oct 2006 13:02:24 -0000 Received: (qmail 30622 invoked from network); 11 Oct 2006 13:02:24 -0000 Received: from mailfe04.tele2.fr (HELO swip.net) (212.247.154.108) by a.mx.sunsite.dk with SMTP; 11 Oct 2006 13:02:20 -0000 X-T2-Posting-ID: mBXjJ9CYMpI3HGlT2s4LT8j3JzBVs7ioB0ePn7y7rgg= X-Cloudmark-Score: 0.000000 [] Received: from [80.170.35.111] (HELO localhost) by mailfe04.swip.net (CommuniGate Pro SMTP 5.0.8) with ESMTPS id 296661426 for zsh-users@sunsite.dk; Wed, 11 Oct 2006 15:02:19 +0200 Date: Wed, 11 Oct 2006 15:02:13 +0200 From: "arno." To: zsh-users@sunsite.dk Subject: pattern matching question Message-ID: <20061011130213.GA6307@localhost.localdomain> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="oyUTqETQ0mS9luUI" Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello, I have an array, for example:=20 local -a list list=3D("... one giraffe ..." "... two cows ..." "... one monkey ..." "... = three lemmings ...") ("..." can represent anything) and I want to get parts of each item each time a specific pattern=20 occurs. For example, I want to get the word after "one". I therefore=20 want to finish with an array containing ("giraffe" "monkey") I found a way with a loop : local -a secondlist local item for item in $list; do if [[ $item =3D (#b)*one\ ([a-z]#)* ]]; then secondlist=3D($secondlist $match[1]) fi done print -l $secondlist Great, works fine. But I was wondering if there was something more zsh-ish that could allow=20 me to do it in one instruction. I found : print -l ${${(M)list##*one ([a-z]#)*}//(#b)*one ([a-z]#)*/$match[1]} but I think this is inefficient as the pattern has to be evaluated=20 twice. What would be the better way to do that ? thanks --oyUTqETQ0mS9luUI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQFFLOtViH9aBScBsrMRAt9EAJ43sMtpnQjyA962rFmfL+SZQTMgCACfejvX jg+xOUc74xtS3+qWZsxrnHQ= =2g8R -----END PGP SIGNATURE----- --oyUTqETQ0mS9luUI--