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]}}";
> 
> ~ echo "__wrd2: $__wrd2, match[1]: ${match[1]}, match[2]: ${match[2]},
> match[3]: ${match[3]}"; echo $?
> 
> __wrd2:  'Finished' }', match[1]: echo abc | awk '{ print $1 } END { ,
> match[2]: print, match[3]:  'Finished' }'
> 
> As it can be seen, match[1] obtains almost whole string. The matching
> is ungreedy, why `print' isn't matched? Why matching continues to last
> keyword, "END", skipping "print"

You've got a "*" at the beginning and the end  They're both doing
matching --- they're is no single "matching" to which a rule applies ,
there are just separate patterns all attempting to match.  You're going
to have to work out some way of forcing one of them to match more than
the other.

pws



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