From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13806 invoked by alias); 15 May 2014 12:26:58 -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: 18818 Received: (qmail 13104 invoked from network); 15 May 2014 12:26:43 -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 14:26:41 +0200 From: Roman Neuhauser To: zsh-users@zsh.org Subject: ${name/pattern/repl} with negated pattern Message-ID: <20140515122641.GI1629@isis.sigpipe.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) this snippet in zshcontrib(1): for i in "$@"; do if [[ $i == sh/* ]]; then [[ -n $s ]] && s=$s, s=${s}$i fi done can be reduced to s=${(j:,:)${@/#(^sh)\/*}} i *thought*, based on the man page, that this would work as well: s=${(j:,:)${@/#^sh\/*}} alas: > 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? zshexpn(1) suggests parentheses are not required: ^x (Requires EXTENDED_GLOB to be set.) Matches anything except the pattern x. This has a higher precedence than `/', so `^foo/bar' will search directories in `.' except `./foo' for a file named `bar'. though this description of a ksh glob operator is suspicious: !(...) Match anything but the expression in parentheses. (Like `(^(...))'.) while i'm here: the whole workaround is cumbersome, you need to negate the pattern (might be difficult in some cases) and actually get as many items back as are in the input array (thus the nested parameter expansion, ${(j:,:)a/#(^x)\/*} produces "x/foo,,x/baz,"). i hoped zsh would have a direct way to expand only those items of an array that match a pattern, eg. ${@:/#sh\/*}. doable? -- roman