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

Re: Non-greedy matching (S-flag) behaving weird



On Fri, 8 Jun 2018 14:30:12 +0100
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Fri, 8 Jun 2018 08:48:05 +0200
> Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> >
> > ~ __wrd2="echo abc | awk '{ print \$1 } END { print 'Finished' }'"
> > 
> > ~
> > __wrd2="${(S)__wrd2/(#b)(#s)(*)(BEGIN|END|print)(*)(#e)/${match[3]}}";  
>
> You are onto a loser with multiple *'s with the greedy match rule
> relaxed; it's poorly defined. so the fact it's not doing what you
> expect isn't saying anything.  (That's why the greedy match rule
> is there in the first place.)  But you'll be better off consulting
> a more authoritative source than me if you want more, so I'll
> sign off now.

I should probably point out, though, that the (S) flag in any
case only guarantees to make the match for the *whole* left part of
the /.../... expression as short as possible.  Given you're forcing it
to match the entire string in any case, it has no effect.
It is not documented to match *individual parts* of the match
expression in any particular way.  So actually my remarks on non-greedy
matching aren't relevant.  Sorry I didn't check the doc earlier
instead of spreading unnecessary confusion.

pws



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