From: Bart Schaefer <schaefer@brasslantern.com>
To: Eric Smith <es@fruitcom.com>, Zsh Users <zsh-users@sunsite.dk>
Subject: Re: list all except
Date: Fri, 4 Feb 2005 17:44:26 +0000 [thread overview]
Message-ID: <1050204174426.ZM15180@candle.brasslantern.com> (raw)
In-Reply-To: <20050204113026.GA4217@fruitcom.com>
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
next prev parent reply other threads:[~2005-02-04 21:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-04 11:30 Eric Smith
2005-02-04 16:16 ` Christian Schneider
2005-02-04 16:30 ` Peter Stephenson
2005-02-04 16:55 ` J
2005-02-04 17:44 ` Bart Schaefer [this message]
2005-02-05 21:50 ` zzapper
2005-02-06 0:23 ` Bart Schaefer
[not found] ` <ce7c01ph81j1tgrmtplb3hqj8lajgsvsr4@4ax.com>
2005-02-06 18:06 ` Bart Schaefer
2005-02-06 19:02 ` zzapper
2005-02-07 12:37 ` zzapper
2005-02-07 15:46 ` Bart Schaefer
2005-02-07 16:14 ` zzapper
2005-02-11 8:34 ` zzapper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1050204174426.ZM15180@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=es@fruitcom.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).