From: Mikael Magnusson <mikachu@gmail.com>
To: Philippe Troin <phil@fifi.org>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Example of use of (S) flag
Date: Mon, 28 Dec 2015 20:13:05 +0100 [thread overview]
Message-ID: <CAHYJk3RHpfHLGw0yaJmRAdoxgN1DSD6kUCA+NKJcfUZyj+Xmuw@mail.gmail.com> (raw)
In-Reply-To: <1451326987.5990.3.camel@ceramic.home.fifi.org>
On Mon, Dec 28, 2015 at 7:23 PM, Philippe Troin <phil@fifi.org> wrote:
> On Wed, 2015-12-23 at 21:01 -0800, Bart Schaefer wrote:
>> Further note that (MS) is sort of a dumbed-down form of backreferences,
>> returning something similar to the value of $MATCH in an extendeglob
>> pattern that uses (#m) (except extendedglob is not needed). E.g.:
>
> 8< snip >8
>
>> torch% echo ${(S)a/b*/x}
>> axcba
>> torch% echo ${(S)a//b*/x}
>> axcxa
>
> I don't understand why in these two examples the star doesn't match the
> rest of the string? I'd expect:
>
> % echo $a
> abcba
> % echo ${(S)a/b*/x}
> ax
> % echo ${(S)a//b*/x}
> ax
>
> Since b* should match the entire bcba substring.
> What did I miss?
(S) also enables shortest possible match (like # does and ## doesn't).
% a=abiibybeebz
% echo ${a/b*b/x}
axz
% echo ${(S)a/b*b/x}
axybeebz
% echo ${(S)a//b*b/x}
axyxz
% echo ${a#*b}
iibybeebz
% echo ${a##*b}
z
S Search substrings as well as beginnings or ends; with # start
from the beginning and with % start from the end of the string. With
substitution via ${.../...} or ${...//...}, specifies non-greedy
matching, i.e. that the shortest instead of the longest match should
be replaced.
--
Mikael Magnusson
next prev parent reply other threads:[~2015-12-28 19:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAKc7PVBLdXYQ_NNU9q=v9TcfiZjsYKfDt2h=ZBdfGCt6t81cuQ__14537.6145992943$1450895198$gmane$org@mail.gmail.com>
2015-12-23 23:25 ` Stephane Chazelas
2015-12-24 5:01 ` Bart Schaefer
2015-12-24 7:53 ` Sebastian Gniazdowski
2015-12-28 18:23 ` Philippe Troin
2015-12-28 19:13 ` Mikael Magnusson [this message]
2015-12-23 18:25 Sebastian Gniazdowski
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=CAHYJk3RHpfHLGw0yaJmRAdoxgN1DSD6kUCA+NKJcfUZyj+Xmuw@mail.gmail.com \
--to=mikachu@gmail.com \
--cc=phil@fifi.org \
--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).