zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: [[ 'abcde' =~ (#i)Bcd ]]
Date: Tue, 8 Nov 2022 09:19:04 +0100	[thread overview]
Message-ID: <CAN=4vMp071_rBgV+noQN9L4nGQ3Oz56si_bnbUU4gQBk1MZHtw@mail.gmail.com> (raw)
In-Reply-To: <29b06e8a-e58a-91c6-985d-64020727d603@eastlink.ca>

On Tue, Nov 8, 2022 at 3:06 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
>
> On 2022-11-07 13:50, Lawrence Velázquez wrote:
> > I concur with Roman. I doubt you actually need case-insensitive
> > regex.
> >
> I'm happy with what I've got working at the moment tho you guys would
> probably improve it.  Pardon my personal jargon but:
>
> local vvar=$( basename $cc[$aa] 2> /dev/null )

There is a zsh way for this:

  local var=${cc[$aa]:t}

"t" is short for tail. There is also "h" for head.

> if   [[ "$scope_msg" = 'BROAD' && $vvar = (#i)*$filter* ]]; then
> elif [[ "$scope_msg" = 'Case INsensitive TAME' && $vvar:u = $filter:u
> ]]; then
> elif [[ "$scope_msg" = 'Case Sensitive WILD' && $vvar =~ $filter ]]; then
> elif [[ "$scope_msg" = 'EXACT' && $vvar = $filter ]]; then
> else cc[$aa]=
> fi

Here WILD suggests a wildcard (a.k.a. glob, a.k.a. pattern) match, but
the code is doing a regex match. If your intention is to perform a
wildcard/glob/pattern match, do this:

    [[ $vvar == $~filter ]]

Or, if you want to always perform a partial match:

    [[ $vvar == *$~filter* ]]

Other cases in your if-else chain also look suspiciously
non-orthogonal. The orthogonal bits of matching are:

1. Pattern matching or regex?
2. Case sensitive or not?
3. Partial or full?

There are a total of 8 combinations. If you drop regex (which you
probably want to do), it leaves 4 combinations.

    [[ $data == $~pattern ]]  # case sensitive, full
    [[ $data == (#i)$~pattern ]]  # case insensitive, full
    [[ $data == *$~pattern* ]]  # case sensitive, partial
    [[ $data == (#i)*$~pattern* ]]  # case insensitive, partial

Note that you don't need to quote $data here (although you can, if you
prefer to do it for stylistic reasons).

> ... the function let's me search for directories with automatic
> wildcards and/or case sensitivity  or both or neither.

There might be a better way to do this which would take advantage of
**/*. It's hard to say without knowing what you are trying to achieve.

Roman.


  reply	other threads:[~2022-11-08  8:20 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
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 [this message]
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='CAN=4vMp071_rBgV+noQN9L4nGQ3Oz56si_bnbUU4gQBk1MZHtw@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --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).