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

Re: non-greedy matching?



--- Adam Spiers <adam@xxxxxxxxxx> wrote: 
> Any ideas?  The only alternatives I've come up with are:
> 
>   foo=$(print -P "$prompt_string")
>   bar="${foo//^[[[0-9;]##m/}"

I should have thought about this before replying the first time but I
didn't until after Sven's e-mail. If you have extendedglob set, you can
do:
${(%%)${PS1//%\{(^*%\}*)%\}/}}
Doing the replace before the prompt expansion allows this to match the
%{...%} instead of the escape sequence. If you have any parameters
which when substituted include escape sequences, you may need to use
(e) before PS1 to expand these first. I trust this more than the sed
because it can do (^*%\}*) which matches anything which doesn't contain
%} to force the non-greedy behaviour.

Oliver

____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie



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