zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Jerry Rocteur <macosx@rocteur.cc>
Cc: Peter Stephenson <pws@csr.com>, zsh-workers@sunsite.dk
Subject: Re: Regexp type pattern matching
Date: Thu, 8 May 2008 10:50:24 +0100	[thread overview]
Message-ID: <20080508095024.GB8133@sc.homeunix.net> (raw)
In-Reply-To: <64874.153.98.68.197.1210237779.squirrel@webmail.rocteur.com>

On Thu, May 08, 2008 at 11:09:39AM +0200, Jerry Rocteur wrote:
[...]
> >   if [[ $USER_NAME = [prt][0-9]* ]]; then
> >     ...
> >   fi
[...]
> you know I tried that but instead of = I put =~ and it did not work.

=~ works with recent versions of zsh and if you have the
zsh/pcre module, you can use perl-like regexps with setopt
re_match_pcre.

[[ $USER_NAME =~ ^[prt][0-9]* ]]

[[ string = pattern ]]

treats pattern as a zsh globbing shell pattern.

zsh patterns are equivalent to regexp (with additions) when the
extended-glob option is on, only with a different syntax.

Here is a quick table of correspondance:

RE      zsh
.	?
*	#
+	##
?	(<pattern>|)
|	|
()	()
^	implied
$	implied
[]	[]
(i:...) (#i)
...

> Thanks very much for this information I really appreciate it.
> 
> Jerry
> P.S. Can you please tell me which manual this [[ $USER_NAME =
> [prt][0-9]* ]] is explained, I looked this morning for a
> few hours and I didn't seen anything like this ?

If you type "info zsh", then "i", then "condi<Tab><Tab>", you'll
see:

3 completions:
condition, completion style    conditional expression
conditional expressions

Select "conditional expressions"

"i" is for "index". You can do the same with the table of
content with the "g" key. The index works better with version
4.12 and above of info.

You can also search the whole manual (with regexps with 4.12)
with the "s" key.

All the key bindings are fully configurable, so if like me, you
don't like the emacs-like key-binding, you can change it.

In any case, remember that what makes the power of "info" is "i"
and "g" (with <Tab>). With a well written manual like zsh, 99%
of the time, I get to the information I'm looking for in a few
keystrokes.

-- 
Stéphane


      reply	other threads:[~2008-05-08  9:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08  8:48 Jerry Rocteur
2008-05-08  9:00 ` Peter Stephenson
2008-05-08  9:09   ` Jerry Rocteur
2008-05-08  9:50     ` Stephane Chazelas [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=20080508095024.GB8133@sc.homeunix.net \
    --to=stephane_chazelas@yahoo.fr \
    --cc=macosx@rocteur.cc \
    --cc=pws@csr.com \
    --cc=zsh-workers@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).