From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11215 invoked by alias); 15 May 2014 16:37:54 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18824 Received: (qmail 21698 invoked from network); 15 May 2014 16:37:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Date: Thu, 15 May 2014 18:37:45 +0200 From: Roman Neuhauser To: Bart Schaefer Cc: zsh-users@zsh.org Subject: Re: ${name/pattern/repl} with negated pattern Message-ID: <20140515163745.GJ1629@isis.sigpipe.cz> References: <20140515122641.GI1629@isis.sigpipe.cz> <140515084550.ZM30494@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <140515084550.ZM30494@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) # schaefer@brasslantern.com / 2014-05-15 08:45:50 -0700: > On May 15, 2:26pm, Roman Neuhauser wrote: > } > } > a=(x/foo y/bar x/baz y/qux) > } > echo ${a/#(^x)\/*} # ok > } x/foo x/baz > } > echo ${a/#^x\/*} # wtf > } /foo /baz > } > } what's happening here? > > You've forgotten that parameter expansion is a pattern match rather than > a filename glob and that slashes have no special significance in pattern > matching, so ^x\/* is ^(x\/*) despite the "higher precedence" mention. no, i know the manpage says / is only special in filename generation. sorry for being so implicit with the question, i should know better. why does it remove the initial "x" from "x/foo" and "x/baz"? > } i hoped zsh would have a direct way to expand only those items of an > } array that match a pattern, eg. ${@:/#sh\/*}. > > Not sure what #sh\/* means (you can't start an extendedglob pattern with > the "#" repetition operator, though for some reason parameter expansion > doesn't gripe about it) zshexpn(1): ${name/pattern/repl} ${name//pattern/repl} [...] The pattern may begin with a `#', in which case the pattern must match at the start of the string, or `%', in which case it must match at the end of the string, or `#%' in which case the pattern must match the entire string. > but the (M) qualifier with the :# susbstition > should do what you want: > > ${(M)@:#pattern} exactly what i'm after, thank you! -- roman