zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh-workers <zsh-workers@sunsite.dk>
Subject: Re: Regexp replace on all arguments.
Date: Sat, 11 Feb 2006 19:20:04 +0000	[thread overview]
Message-ID: <1060211192004.ZM6032@candle.brasslantern.com> (raw)
In-Reply-To: <20060211182105.GA7789@lxlabs.com>

On Feb 11, 11:51pm, Ligesh wrote:
> Subject: Re: Regexp replace on all arguments.
>
> On Sat, Feb 11, 2006 at 05:38:19PM +0000, Stephane Chazelas wrote:
> > winexec() {
> >   local cmd=$1
> >   shift || return
> >   argv=("${@//#\/(#b)([a-zA-Z])\//$match:}")
> >   "$cmd" "$@"
> > }
> > 
>
>  I couldn't get it to work. There is no substitution happening at all.

    winexec () {
        setopt localoptions extendedglob
        local cmd=$1
        shift || return
        argv=("${@//#\/(#b)([a-zA-Z])\//$match:}")
        "$cmd" "$@"
    }

>   What's the /#?

You're parsing it wrong.

 @                      The variable to expand
 //                     Replace all occurrences of
 #\/(#b)([a-zA-Z])\/    this pattern
 /                      with
 $match:                this expansion (see "backreference" below)

>   what's (#b)?

The pattern is

 #                      Anchor at beginning
 \/                     a slash
 (#b)                   activate "backreferences"
 ([a-zA-Z])             create a backreference to one alphabetic
 \/                     another slash

The backreference stuff requires extendedglob.  It's actually not
useful to use the // for replace-all because there can only be one
match when anchored at the beginning, so just ${@/#.../...} would
have been OK.

(This question really should have been asked on zsh-users.)


      reply	other threads:[~2006-02-11 19:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-11 17:36 Ligesh
2006-02-11 17:38 ` Stephane Chazelas
2006-02-11 18:21   ` Ligesh
2006-02-11 19:20     ` Bart Schaefer [this message]

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=1060211192004.ZM6032@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /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).