Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: list all except
- X-seq: zsh-users 8463
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Eric Smith <es@xxxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Re: list all except
- Date: Fri, 4 Feb 2005 17:44:26 +0000
- In-reply-to: <20050204113026.GA4217@xxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20050204113026.GA4217@xxxxxxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author