zsh-users
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: zsh-users@zsh.org
Subject: Re: Regular expressions in zsh
Date: Thu, 24 Feb 2011 06:21:14 -0500	[thread overview]
Message-ID: <20110224112114.GA14026@redoubt.spodhuis.org> (raw)
In-Reply-To: <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.


      parent reply	other threads:[~2011-02-24 11:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-19  3:38 Vincent Stemen
2011-02-19  5:48 ` Phil Pennock
2011-02-23 16:41   ` zzapper
2011-02-24 10:28     ` zzapper
2011-02-24 11:21     ` Phil Pennock [this message]

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=20110224112114.GA14026@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=zsh-users@zsh.org \
    /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).