zsh-users
 help / color / mirror / code / Atom feed
* Re: Example of use of (S) flag
       [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
  0 siblings, 1 reply; 6+ messages in thread
From: Stephane Chazelas @ 2015-12-23 23:25 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: zsh-users

2015-12-23 19:25:05 +0100, Sebastian Gniazdowski:
> Hello,
> completion says that (S) is "search substrings in #, %, /
> expressions". Can someone provide example of (S) influence? Thanks
[...]

$ a=ababa
$ echo ${(S)a#b}
aaba
$ echo ${(S)a%b}
abaa


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Example of use of (S) flag
  2015-12-23 23:25 ` Example of use of (S) flag Stephane Chazelas
@ 2015-12-24  5:01   ` Bart Schaefer
  2015-12-24  7:53     ` Sebastian Gniazdowski
  2015-12-28 18:23     ` Philippe Troin
  0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 2015-12-24  5:01 UTC (permalink / raw)
  To: zsh-users

On Dec 23, 11:25pm, Stephane Chazelas wrote:
} Subject: Re: Example of use of (S) flag
}
} 2015-12-23 19:25:05 +0100, Sebastian Gniazdowski:
} > Hello,
} > completion says that (S) is "search substrings in #, %, /
} > expressions". Can someone provide example of (S) influence? Thanks
} [...]
} 
} $ a=ababa
} $ echo ${(S)a#b}
} aaba
} $ echo ${(S)a%b}
} abaa

Note also that ${(S)var:#pat} is not useful; pat must still match the
entire value of $var (or an element of $var in the array case) for the
element to be matched/removed.

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.:

% a=abcba
% echo ${(MS)a#b?}
bc
% echo ${(MS)a%b?}
ba

Here are some examples of the use with ${var/pat/repl}:

torch% echo ${a/b*/x}    
ax
torch% echo ${(S)a/b*/x}
axcba
torch% echo ${(S)a//b*/x}
axcxa


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Example of use of (S) flag
  2015-12-24  5:01   ` Bart Schaefer
@ 2015-12-24  7:53     ` Sebastian Gniazdowski
  2015-12-28 18:23     ` Philippe Troin
  1 sibling, 0 replies; 6+ messages in thread
From: Sebastian Gniazdowski @ 2015-12-24  7:53 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

On 24 December 2015 at 06:01, Bart Schaefer <schaefer@brasslantern.com> wrote:
> Note also that ${(S)var:#pat} is not useful; pat must still match the
> entire value of $var (or an element of $var in the array case) for the
> element to be matched/removed.

Too bad, my original intention was to do what list=(
"${(@M)list:#(#i)*$~search_pattern*}" ) does but with (S) and compare
performance of the two. Was surprised that this list=(
"${(@SM)list:#(#i)$~search_pattern}" ) doesn't work.

Best regards,
Sebastian Gniazdowski


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Example of use of (S) flag
  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
  1 sibling, 1 reply; 6+ messages in thread
From: Philippe Troin @ 2015-12-28 18:23 UTC (permalink / raw)
  To: zsh-users

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?

Phil.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Example of use of (S) flag
  2015-12-28 18:23     ` Philippe Troin
@ 2015-12-28 19:13       ` Mikael Magnusson
  0 siblings, 0 replies; 6+ messages in thread
From: Mikael Magnusson @ 2015-12-28 19:13 UTC (permalink / raw)
  To: Philippe Troin; +Cc: Zsh Users

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Example of use of (S) flag
@ 2015-12-23 18:25 Sebastian Gniazdowski
  0 siblings, 0 replies; 6+ messages in thread
From: Sebastian Gniazdowski @ 2015-12-23 18:25 UTC (permalink / raw)
  To: zsh-users

Hello,
completion says that (S) is "search substrings in #, %, /
expressions". Can someone provide example of (S) influence? Thanks

Best regards,
Sebastian Gniazdowski


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-28 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAKc7PVBLdXYQ_NNU9q=v9TcfiZjsYKfDt2h=ZBdfGCt6t81cuQ__14537.6145992943$1450895198$gmane$org@mail.gmail.com>
2015-12-23 23:25 ` Example of use of (S) flag 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
2015-12-23 18:25 Sebastian Gniazdowski

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).