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 08:48:05 +0200
Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> below subsitution is a really easy one. First parenthesis: anything
> preceding, second parenthesis: print|END|BEGIN, third parenthesis:
> anything that follows print|END etc.
> 
> ~ __wrd2="echo abc | awk '{ print \$1 } END { print 'Finished' }'"
> 
> ~
> __wrd2="${(S)__wrd2/(#b)(#s)(*)(BEGIN|END|print)(*)(#e)/${match[3]}}";

I think what you're trying to do is:

print ${__wrd2#*(BEGIN|END|print)}

(or some variation thereon).

This is now well defined --- there's only one expression matching
an arbitrary number of parameters, and you've explicitly told it to
shorten from the end of the string to resolve multiple matches.

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.

pws



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