From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19605 invoked from network); 4 Feb 2005 21:14:55 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 4 Feb 2005 21:14:55 -0000 Received: (qmail 48409 invoked from network); 4 Feb 2005 21:13:17 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 Feb 2005 21:13:17 -0000 Received: (qmail 28725 invoked by alias); 4 Feb 2005 17:45:17 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8463 Received: (qmail 28716 invoked from network); 4 Feb 2005 17:45:16 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 4 Feb 2005 17:45:16 -0000 Received: (qmail 63756 invoked from network); 4 Feb 2005 17:44:40 -0000 Received: from out009pub.verizon.net (HELO out009.verizon.net) (206.46.170.131) by a.mx.sunsite.dk with SMTP; 4 Feb 2005 17:44:34 -0000 Received: from candle.brasslantern.com ([4.11.10.129]) by out009.verizon.net (InterMail vM.5.01.06.06 201-253-122-130-106-20030910) with ESMTP id <20050204174432.LGCA4172.out009.verizon.net@candle.brasslantern.com>; Fri, 4 Feb 2005 11:44:32 -0600 Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j14HiRlu015182; Fri, 4 Feb 2005 09:44:27 -0800 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j14HiRTJ015181; Fri, 4 Feb 2005 09:44:27 -0800 From: Bart Schaefer Message-Id: <1050204174426.ZM15180@candle.brasslantern.com> Date: Fri, 4 Feb 2005 17:44:26 +0000 In-Reply-To: <20050204113026.GA4217@fruitcom.com> Comments: In reply to Eric Smith "list all except" (Feb 4, 12:30pm) References: <20050204113026.GA4217@fruitcom.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Eric Smith , Zsh Users Subject: Re: list all except MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Authentication-Info: Submitted using SMTP AUTH at out009.verizon.net from [4.11.10.129] at Fri, 4 Feb 2005 11:44:28 -0600 X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On Feb 4, 12:30pm, Eric Smith wrote: } } What is the zsh way to select all files except } those matching a regex? Careful with the term "regex". Although zsh extendedglob patterns are semantically equivalent to regular expressions, they don't follow the usual regular expression syntax. Which do you really mean? If you literally mean a perl-like regular expression, and you have the pcre module available, it'd be something like: zmodload zsh/pcre setopt extendedglob pcre_compile "negpat" echo *(e:'pcre_match "$REPLY" && reply=() || reply=($REPLY)':) (replacing "negpat" with your desired regex, obviously). The more usual way would be to write it as one of two forms of glob pattern: ^negpat (requires extendedglob) pospat~negpat The differences are subtle, and get two whole pages [*] in "From Bash to Zsh". The first matches any file name other than "negpat". The second matches file names with "pospat", then removes those strings that match "negpat". The first matches files within a single level of directory hierarchy. The negpat part of the second can match across directories, if the pospat part contains slashes. These differences are especially important if you combine the ^negpat form with other patterns, e.g., as in xyz(^PDQ)*, which will match xyzPDQzyx because the empty substring between xyz and PDQ is a match for (^PDQ) and PDQzyx is matched by "*". The pcre_match example above works mostly like the pospat~negpat form, because files are first found by globbing and then discarded by pattern matching; but pcre_match is invoked as each file is examined, whereas in pospat~negpat the string removal is done at the end after globbing has finished. This could be important if the pospat uses **/ for tree searching. [*] But not two consecutive pages. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net