Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Regexp replace on all arguments.



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.)



Messages sorted by: Reverse Date, Date, Thread, Author