Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [[ 'abcde' =~ (#i)Bcd ]]
On Mon, Nov 7, 2022, at 4:47 PM, Ray Andrews wrote:
> On 2022-11-07 13:26, Roman Perepelitsa wrote:
>> [[ 'abcde' =~ (#i)Bcd ]] && echo match3
>
>> (#i) only works with pattern matching.
>
> But isn't that a pattern match?
No. It is a regular expression match. When discussing shells and
adjacent tools, "pattern" almost always implies the syntax used for
filename generation, or an extension thereof. (I only say "almost"
as a hedge.)
> [[ 'abcde' = (#i)ABcde ]] && echo match2
>
> ... that seems happy so it would seem that wildcards aren't required.
They are required if you want a partial-length match.
% [[ abcde = (#i)ABcde ]]; print $?
0
% [[ abcde = (#i)Bcd ]]; print $?
1
% [[ abcde = (#i)*Bcd* ]]; print $?
0
>> In this specific case it's better to use pattern matching of course:
>>
>> [[ $foo == (#i)*abc* ]] && echo match
>>
> That's what puzzles me I expect:
>
> [[ $foo == (#i)*abc* ]] && echo match
>
> and:
>
> [[ $foo =~ (#i)abc ]] && echo match
>
> ... to be exactly the same. If not, why not?
Glob qualifiers only work with globs.
Regular expression matching is done using an external library (either
PCRE or the host regex library). These libraries can hardly be
expected to understand zsh glob qualifiers.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author