zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: "Ray Andrews" <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: [[ 'abcde' =~ (#i)Bcd ]]
Date: Mon, 07 Nov 2022 17:15:37 -0500	[thread overview]
Message-ID: <35e0a559-c6dd-41c2-a264-3e9d4846979e@app.fastmail.com> (raw)
In-Reply-To: <b7e5f243-df5d-6836-35b1-df95ecf8f820@eastlink.ca>

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


  reply	other threads:[~2022-11-07 22:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 21:10 Ray Andrews
2022-11-07 21:26 ` Roman Perepelitsa
2022-11-07 21:47   ` Ray Andrews
2022-11-07 22:15     ` Lawrence Velázquez [this message]
2022-11-08  1:57       ` Ray Andrews
2022-11-07 21:50   ` Lawrence Velázquez
2022-11-08  2:05     ` Ray Andrews
2022-11-08  8:19       ` Roman Perepelitsa
2022-11-08 13:32         ` Ray Andrews
2022-11-08 14:37           ` Roman Perepelitsa
2022-11-08 14:30             ` Ray Andrews
2022-11-08 17:40 ` Phil Pennock
2022-11-08 18:43   ` Ray Andrews

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=35e0a559-c6dd-41c2-a264-3e9d4846979e@app.fastmail.com \
    --to=larryv@zsh.org \
    --cc=rayandrews@eastlink.ca \
    --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).