Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Regexp replace on all arguments.
- X-seq: zsh-workers 22232
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh-workers <zsh-workers@xxxxxxxxxx>
- Subject: Re: Regexp replace on all arguments.
- Date: Sat, 11 Feb 2006 19:20:04 +0000
- In-reply-to: <20060211182105.GA7789@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20060211173626.GA6863@xxxxxxxxxx> <20060211173818.GA4965@sc> <20060211182105.GA7789@xxxxxxxxxx>
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