* Why no $match for parens inside a ~^ ?
@ 2023-01-25 14:50 Sebastian Gniazdowski
2023-01-25 14:52 ` Sebastian Gniazdowski
0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-25 14:50 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 439 bytes --]
Hi,
I'm matching a pattern:
[[ "zparseopts -F" == *(zparseopts)*~^*(-F)* ]]
printf →%s\\n $? "$match[@]"
with output:
→0
→zparseopts
→
I would want \3 to contain -F… because, I would once want to use (-F|)
there, and be able to test if the option is given… Is it possible?
~^ is a double negation that makes the pattern work like "if-contains
zparseopts AND -F"
--
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: Type: text/html, Size: 1448 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Why no $match for parens inside a ~^ ?
2023-01-25 14:50 Why no $match for parens inside a ~^ ? Sebastian Gniazdowski
@ 2023-01-25 14:52 ` Sebastian Gniazdowski
2023-01-25 16:31 ` Sebastian Gniazdowski
2023-01-25 22:05 ` Bart Schaefer
0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-25 14:52 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 778 bytes --]
PS. (#b) is missing in the pattern, correct code is:
[[ "zparseopts -F" == (#b)*(zparseopts)*~^*(-F)* ]]
printf →%s\\n $? "$match[@]"
output is the same.
On Wed, 25 Jan 2023 at 14:50, Sebastian Gniazdowski <sgniazdowski@gmail.com>
wrote:
> Hi,
> I'm matching a pattern:
> [[ "zparseopts -F" == *(zparseopts)*~^*(-F)* ]]
> printf →%s\\n $? "$match[@]"
>
> with output:
> →0
> →zparseopts
> →
>
> I would want \3 to contain -F… because, I would once want to use (-F|)
> there, and be able to test if the option is given… Is it possible?
>
> ~^ is a double negation that makes the pattern work like "if-contains
> zparseopts AND -F"
>
>
> --
> Best regards,
> Sebastian Gniazdowski
>
>
--
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: Type: text/html, Size: 2364 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Why no $match for parens inside a ~^ ?
2023-01-25 14:52 ` Sebastian Gniazdowski
@ 2023-01-25 16:31 ` Sebastian Gniazdowski
2023-01-25 22:05 ` Bart Schaefer
1 sibling, 0 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-25 16:31 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 2097 bytes --]
I've found a workaround for testing of -F has been given in one go – via
the super cool negation `~`:
QE='zparseopts qqq -F afwe'
print ${QE//(#b)zparseopts(*~*-F*~*-)(-F|)*/°match°}
printf °%s\\n "$match[@]" $?
Output:
°match°
° qqq
°-F
°0
So the -F exists there in $match[3] for testing if it has been given to
zparseopts. The main point is the ~ rejection of -F on part of the input
string:
…(*~*-F*~*-)…
It translates: everything (*) but not -F (~*-F*) and in that subset, also
not dash = (~*-). Without the ~*- it would match "not -F", so "-" from
within it is still allowed:
QE='zparseopts qqq -F afwe'
print ${QE//(#b)zparseopts(*~*-F*)(-F|)*/°match°}
printf °%s\\n "$match[@]" $?
Output:
°match°
° qqq -
°
°0
With it and with ~*-F* it correctly accepts other options:
QE='zparseopts qqq -q -F afwe'
print ${QE//(#b)zparseopts(*~*-F*~*-)(-F|)*/°match°}
printf °%s\\n "$match[@]" $?
Output:
°match°
° qqq -q
°-F
°0
I think that this demonstrates the uniqueness of Zsh pattern negations.
That really should be available in regexps.
On Wed, 25 Jan 2023 at 14:52, Sebastian Gniazdowski <sgniazdowski@gmail.com>
wrote:
> PS. (#b) is missing in the pattern, correct code is:
> [[ "zparseopts -F" == (#b)*(zparseopts)*~^*(-F)* ]]
> printf →%s\\n $? "$match[@]"
>
> output is the same.
>
>
> On Wed, 25 Jan 2023 at 14:50, Sebastian Gniazdowski <
> sgniazdowski@gmail.com> wrote:
>
>> Hi,
>> I'm matching a pattern:
>> [[ "zparseopts -F" == *(zparseopts)*~^*(-F)* ]]
>> printf →%s\\n $? "$match[@]"
>>
>> with output:
>> →0
>> →zparseopts
>> →
>>
>> I would want \3 to contain -F… because, I would once want to use (-F|)
>> there, and be able to test if the option is given… Is it possible?
>>
>> ~^ is a double negation that makes the pattern work like "if-contains
>> zparseopts AND -F"
>>
>>
>> --
>> Best regards,
>> Sebastian Gniazdowski
>>
>>
>
> --
> Best regards,
> Sebastian Gniazdowski
>
>
--
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: Type: text/html, Size: 6473 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Why no $match for parens inside a ~^ ?
2023-01-25 14:52 ` Sebastian Gniazdowski
2023-01-25 16:31 ` Sebastian Gniazdowski
@ 2023-01-25 22:05 ` Bart Schaefer
2023-01-26 14:45 ` Sebastian Gniazdowski
1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2023-01-25 22:05 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Zsh Users
On Wed, Jan 25, 2023 at 6:53 AM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> [[ "zparseopts -F" == (#b)*(zparseopts)*~^*(-F)* ]]
I'm not 100% sure, but I think the problem here is that the negation
with ^ is processed in a secondary invocation of the pattern matcher
so the $match from parens there is overwritten by the results of the
previous pattern.
This behaves differently (but perhaps not quite what you're after):
[[ "zparseopts -F" == (#b)*(zparseopts)(*~^*(-F)*) ]]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Why no $match for parens inside a ~^ ?
2023-01-25 22:05 ` Bart Schaefer
@ 2023-01-26 14:45 ` Sebastian Gniazdowski
0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2023-01-26 14:45 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 666 bytes --]
Thanks, this makes sense.
On Wed, 25 Jan 2023 at 22:05, Bart Schaefer <schaefer@brasslantern.com>
wrote:
> On Wed, Jan 25, 2023 at 6:53 AM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > [[ "zparseopts -F" == (#b)*(zparseopts)*~^*(-F)* ]]
>
> I'm not 100% sure, but I think the problem here is that the negation
> with ^ is processed in a secondary invocation of the pattern matcher
> so the $match from parens there is overwritten by the results of the
> previous pattern.
>
> This behaves differently (but perhaps not quite what you're after):
>
> [[ "zparseopts -F" == (#b)*(zparseopts)(*~^*(-F)*) ]]
>
--
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: Type: text/html, Size: 1292 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-01-26 14:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25 14:50 Why no $match for parens inside a ~^ ? Sebastian Gniazdowski
2023-01-25 14:52 ` Sebastian Gniazdowski
2023-01-25 16:31 ` Sebastian Gniazdowski
2023-01-25 22:05 ` Bart Schaefer
2023-01-26 14:45 ` 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).