Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Regexp type pattern matching
- X-seq: zsh-workers 24979
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Jerry Rocteur <macosx@xxxxxxxxxx>
- Subject: Re: Regexp type pattern matching
- Date: Thu, 8 May 2008 10:50:24 +0100
- Cc: Peter Stephenson <pws@xxxxxxx>, zsh-workers@xxxxxxxxxx
- In-reply-to: <64874.153.98.68.197.1210237779.squirrel@xxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Jerry Rocteur <macosx@xxxxxxxxxx>, Peter Stephenson <pws@xxxxxxx>, zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <30735.153.98.68.197.1210236493.squirrel@xxxxxxxxxxxxxxxxxxx> <200805080900.m4890fnu005197@xxxxxxxxxxxxxx> <64874.153.98.68.197.1210237779.squirrel@xxxxxxxxxxxxxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author