zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Non-greedy matching (S-flag) behaving weird
Date: Fri, 8 Jun 2018 08:48:05 +0200	[thread overview]
Message-ID: <CAKc7PVDQcSL2fkot2i6H3YVwcp=q=bQ2DohTdfPGn2p5idH2Sw@mail.gmail.com> (raw)

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


             reply	other threads:[~2018-06-08  6:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180608064952epcas4p4e8890504ddaf097f8d0df1cb1e89d619@epcas4p4.samsung.com>
2018-06-08  6:48 ` Sebastian Gniazdowski [this message]
2018-06-08  8:15   ` Peter Stephenson
2018-06-08 12:42     ` Sebastian Gniazdowski
2018-06-08 12:48       ` Sebastian Gniazdowski
2018-06-08 13:30   ` Peter Stephenson
     [not found]   ` <20180608143012.394398bf@camnpupstephen.cam.scsc.local>
2018-06-08 13:54     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKc7PVDQcSL2fkot2i6H3YVwcp=q=bQ2DohTdfPGn2p5idH2Sw@mail.gmail.com' \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).