[-- Attachment #1: Type: text/plain, Size: 844 bytes --] Hi, the current description is: S -- search substrings in #, %, / expressions which: - is counter the manual and usage-proof, as the flag affects / and // substitutions only in the non-greedy way. The patch changes the description to: S -- match non-greedy in /, // or search substrings in % and # expressions (the referenced manual fragment is: 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.) -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org [-- Attachment #2: 0001-_brace_parameter-Update-the-description-of-S-flag.patch.2.txt --] [-- Type: text/plain, Size: 1089 bytes --] From c0f421ae9988cb125243845eb3acc59847f818b7 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski <sgniazdowski@gmail.com> Date: Mon, 2 Dec 2019 01:16:03 +0100 Subject: [PATCH] _brace_parameter: Update the description of S flag --- Completion/Zsh/Context/_brace_parameter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Completion/Zsh/Context/_brace_parameter b/Completion/Zsh/Context/_brace_parameter index a9ab44efd..c6e74bf7b 100644 --- a/Completion/Zsh/Context/_brace_parameter +++ b/Completion/Zsh/Context/_brace_parameter @@ -177,7 +177,7 @@ if [[ $PREFIX = *'${('[^\)]# ]]; then "s:split words on specified string" "Z:split words as if zsh command line (with options)" # "_:extended flags, for future expansion" - "S:search substrings in #, %, / expressions" + "S:match non-greedy in /, // or search substrings in % and # expressions" "I:search <argument>th match in #, %, / expressions" "B:include index of beginning of match in #, % expressions" "E:include index of one past end of match in #, % expressions" -- 2.21.0
On that occasion, isn't this a bug?: ❯ str="ab##c#d"; print ${(S)str##\#} ab#c#d ❯ str="ab##c#d"; print ${(S)str##\##} ab##c#d Why no match at all in the second case?
On Mon, 2 Dec 2019 at 01:46, Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote: > > On that occasion, isn't this a bug?: > > ❯ str="ab##c#d"; print ${(S)str##\#} > ab#c#d > ❯ str="ab##c#d"; print ${(S)str##\##} > ab##c#d > > Why no match at all in the second case? Any update on this? It would be good that the rarely-used flags are reliable. -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org
On Tue, 2019-12-03 at 06:16 +0100, Sebastian Gniazdowski wrote:
> On Mon, 2 Dec 2019 at 01:46, Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> >
> > On that occasion, isn't this a bug?:
> >
> > ❯ str="ab##c#d"; print ${(S)str##\#}
> > ab#c#d
> > ❯ str="ab##c#d"; print ${(S)str##\##}
> > ab##c#d
> >
> > Why no match at all in the second case?
> Any update on this? It would be good that the rarely-used flags are reliable.
>
You've got an expression which can match an empty string which you're
also telling to match a substring so it can match an empty string
anywhere. The order in which it tries to match will be crucial so this
is not a useful thing to attempt. What are you actually trying to do?
pws
Sebastian Gniazdowski wrote:
> On that occasion, isn't this a bug?:
>
> ❯ str="ab##c#d"; print ${(S)str##\#}
> ab#c#d
> ❯ str="ab##c#d"; print ${(S)str##\##}
> ab##c#d
>
> Why no match at all in the second case?
It does not exhaustively find the longest match. It takes the first
possible match but matches that one greedily. The first possible match
is the empty string at the beginning of the string.
I think the following demonstrates how this works more clearly:
% str="aXXbXXXXXXXXc"; print ${(S)str##X##}
abXXXXXXXXc
This matches the shorter block of Xs between a and b and the greedyness
means that both Xs were matched. ${(S)str#X##} returns aXbXXXXXXXXc.
Oliver
[-- Attachment #1: Type: text/plain, Size: 1178 bytes --] wt., 3 gru 2019, 10:43 użytkownik Peter Stephenson <p.stephenson@samsung.com> napisał: > On Tue, 2019-12-03 at 06:16 +0100, Sebastian Gniazdowski wrote: > > On Mon, 2 Dec 2019 at 01:46, Sebastian Gniazdowski > > <sgniazdowski@gmail.com> wrote: > > > > > > > > > On that occasion, isn't this a bug?: > > > > > > ❯ str="ab##c#d"; print ${(S)str##\#} > > > ab#c#d > > > ❯ str="ab##c#d"; print ${(S)str##\##} > > > ab##c#d > > > > > > Why no match at all in the second case? > > Any update on this? It would be good that the rarely-used flags are > reliable. > > > > You've got an expression which can match an empty string which you're > also telling to match a substring so it can match an empty string > anywhere. The order in which it tries to match will be crucial so this > is not a useful thing to attempt. What are you actually trying to do? > I was expecting that it'll do a greedy match. Turns out, as Oliver writes, that there's something like "nonexhaustive" greedy match which seems to work like (|\###) so this pretty much explains it. I wasn't doing anything particular, just testing the flags before updating the description.