Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Expanding when matching
- X-seq: zsh-users 7402
 
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
 
- To: Zsh Users <zsh-users@xxxxxxxxxx>
 
- Subject: Re: Expanding when matching
 
- Date: Sat, 24 Apr 2004 04:14:14 +0000
 
- In-reply-to: <20040423211540.GA1821@DervishD>
 
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
 
- References: <20040423211540.GA1821@DervishD>
 
On Apr 23, 11:15pm, DervishD wrote:
}
}     $ print ${testvar/#This*%/Replaced}
}     This is my test var
} 
}     The example doesn't make much sense, but it illustrates what I
} mean. What I'm doing wrong? What am I not understanding?
I know Wayne has already answered, but:
The # and % tokens in ${var/pat/rep} are not analogous to regex ^ and $.
Rather, they're analogous to ${var#pat} and ${var%pat}.  Does that help?
For the analogs of ^ and $, you need (#s) and (#e) [and extendedglob].
    $ print ${testvar/(#s)This*var(#e)/Replaced}
} replace some numbers in one text that should be consecutive but are
} not, and they are interspersed with arbitrary text. What I know about
} them is that they are alone in a line, so they match certain regex,
    setopt extendedglob
    c=0; while read line; do print ${${line#<->(#e)}:-$[++c]}; done
(Replacing <-> with your pattern.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author