Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Regular expressions in zsh
- X-seq: zsh-users 15828
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Regular expressions in zsh
- Date: Thu, 24 Feb 2011 06:21:14 -0500
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d200912; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date; bh=utU0FpDgJLZx+dJ7dAX+NuJ6EdRYQ8scxBHDO08BhuQ=; b=S+F2gujBXPbGdynlVgwURekfw4g0I+7dailnboTIz0ttzwg15F55EqXj1HkGYVRCS4sKHYHjXdmTe3zpBVd3Oj0e2GCxKK7IUJRANF8VTMEMsP/RPa/wmzAUbgy779BqExWg5nS/X//3APwTEY5ZzXFs9LxqaQTpGe5qFT1CRZQ=;
- In-reply-to: <Xns9E95A9D1688C0zzappergmailcom@80.91.229.10>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20110219033809.GA72507@quark.hightek.org> <20110219054807.GA57597@redoubt.spodhuis.org> <Xns9E95A9D1688C0zzappergmailcom@80.91.229.10>
On 2011-02-23 at 16:41 +0000, zzapper wrote:
> Have you any illustrative examples of using REMATCH_PCRE?
I keep a shell variable $ipv6_regex defined, with a PCRE regexp that
matches IPv6 addresses. Lots of non-capturing sub-expressions.
You can grab emit_ipv6_regexp from:
http://people.spodhuis.org/phil.pennock/software/
Then it's just:
[[ $foo =~ ^$ipv6_regex\$ ]] && echo IPv6
The other times it matters is when I'm using zero-width assertions,
which are Rather Nice in those situation where you need them.
As a rather contrived example, this will print out the name and value of
all shell variables with "NAME" in their name, except for ZSH_NAME:
for param in ${(k)parameters}; do
[[ $param =~ '(?<!ZSH_)NAME' ]] || continue
echo "$param: ${(P)param}"
done
I don't actually recall what I've used rematch_pcre for, besides the
IPv6 regexp, recently: it's just one of those things that when you need
it, it's very helpful.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author