From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17657 invoked from network); 8 May 2008 09:50:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 8 May 2008 09:50:57 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 70921 invoked from network); 8 May 2008 09:50:52 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 8 May 2008 09:50:52 -0000 Received: (qmail 1869 invoked by alias); 8 May 2008 09:50:49 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24979 Received: (qmail 1854 invoked from network); 8 May 2008 09:50:49 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 8 May 2008 09:50:49 -0000 Received: from mail.o2.co.uk (yoda.london.02.net [82.132.130.151]) by bifrost.dotsrc.org (Postfix) with ESMTP id C58E980ED172 for ; Thu, 8 May 2008 11:50:45 +0200 (CEST) Received: from sc.homeunix.net (78.105.216.138) by mail.o2.co.uk (8.0.013.3) (authenticated as stephane.chazelas) id 480343A7033758D3; Thu, 8 May 2008 10:50:24 +0100 Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1Ju2lc-0002Aw-73; Thu, 08 May 2008 10:50:24 +0100 Date: Thu, 8 May 2008 10:50:24 +0100 From: Stephane Chazelas To: Jerry Rocteur Cc: Peter Stephenson , zsh-workers@sunsite.dk Subject: Re: Regexp type pattern matching Message-ID: <20080508095024.GB8133@sc.homeunix.net> Mail-Followup-To: Jerry Rocteur , Peter Stephenson , zsh-workers@sunsite.dk References: <30735.153.98.68.197.1210236493.squirrel@webmail.rocteur.com> <200805080900.m4890fnu005197@news01.csr.com> <64874.153.98.68.197.1210237779.squirrel@webmail.rocteur.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <64874.153.98.68.197.1210237779.squirrel@webmail.rocteur.com> User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.91.2/7060/Thu May 8 08:07:49 2008 on bifrost X-Virus-Status: Clean 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 . ? * # + ## ? (|) | | () () ^ 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", 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 ). 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