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

Re: Expanding when matching



    Hi Wayne :)

 * Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx> dixit:
> >     $ testvar="This is my test var"
> >     $ print ${testvar/var%/Replaced}
> >     This is my test var
> This should be:
>     $ print ${testvar/%var/Replaced}
>     This is my test Replaced
> The leading '%' indicates that the match must occur at the end.

    I may have read the zsh info section 'Parameter Expansion'
hundreds of times, maybe more, and *always* I've read it, I've come
to the conclusion that the '#' and the '%' were the equivalent to '^'
and '$' in POSIX regexes, which they are not. The problem here is
that I did a bad reading of the manual, sorry :(( Since the symbols
used (# and %) are the same as in other parameter substitutions, that
should have worked as mnemonic O:)

    Again, sorry for the noise, next time I promise to better read
the manual, if I can afford the brain...
 
> > What I want is the substitution (and the postincrement) expanded and
> > run only when the parameter matches
> If you don't need it done in a single line, you can always use "case":

    The problem here is when the regex is not a simple number, but a
more complicated one which needs backrefs and the like when
substituting. Could it be done with 'case'?.

    Thanks a lot for your help, Wayne.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



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