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

Re: pattern matching question

Frank Terbeck wrote:
> list=("... one giraffe ..." "... two cows ..." "... one monkey ..." "... thre
> e lemmings ...")
> slist=(${(M)list:#*one [a-z]*})

To get the exact effect arno wants, you need an additional substitution
to remove the extra stuff, which brings it back to his original
proposal.  I'd probably just do the simple

slist=(${${${(M)list:#*one [a-z]*}##*one }%% *})

which now has two extra pattern matches.

I can't offhand think of a way of both matching the one and extracting
the following word in one go.  In practice it's unlikely to make a
noticeable difference unless you're really doing this a great deal---and
if speed's that important it's probably time to switch to a more
optimized scripting language.

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

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