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

Non-greedy matching (S-flag) behaving weird



Hello,
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"
-- 
Best regards,
Sebastian Gniazdowski



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