From: Roman Neuhauser <neuhauser@sigpipe.cz>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: ${name/pattern/repl} with negated pattern
Date: Thu, 15 May 2014 18:37:45 +0200 [thread overview]
Message-ID: <20140515163745.GJ1629@isis.sigpipe.cz> (raw)
In-Reply-To: <140515084550.ZM30494@torch.brasslantern.com>
# 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
next prev parent reply other threads:[~2014-05-15 16:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-15 12:26 Roman Neuhauser
2014-05-15 15:32 ` Peter Stephenson
2014-05-15 18:18 ` Roman Neuhauser
2014-05-15 15:45 ` Bart Schaefer
2014-05-15 16:37 ` Roman Neuhauser [this message]
2014-05-15 17:16 ` Bart Schaefer
2014-05-15 18:39 ` Roman Neuhauser
2014-05-16 8:40 ` Peter Stephenson
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=20140515163745.GJ1629@isis.sigpipe.cz \
--to=neuhauser@sigpipe.cz \
--cc=schaefer@brasslantern.com \
--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).