From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8835 invoked from network); 8 Nov 2022 08:20:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Nov 2022 08:20:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667895607; b=dsIH7B/TZ6V+N+O0pKYtPq4AzkeQ815fWp3Q7BZ+z0uG8ij/kYhSxLs1r0ydgbS6WUQsrG+pWJ wwYgz9RP76dB2AMUb1jW/FOoGhLh8Rs3JEff9g2WY/6B82tnmMlnaCW1F7HzYtugMMNpZujHa/ ISZ3b7RKHF5iCgnw02e9Nu9TonlzuE9VF5QfaQtYqOGx40wSGRy4QjkWsN1h2Z76Ugcu9HRgoD l1Qn31M50cFBzQCZQJjnauUJ2NtstmqbT9DVHUaWZzlfPTTpo9WoB3RY6YtsnX85zBnsvu7gcK ebPNLdM8LYqJVpICfS7PC45sZj8ntZcJigXC7pDf8V1Rog==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f178.google.com) smtp.remote-ip=209.85.219.178; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1667895607; bh=SFXT/6X8Z4tPYLE2UMiDeL5Vtaippdka87hv7OjQyPA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=rJ3RolTHXeaPvykLPQ6K1Fi6OHmHrshLwCFYYbv4MNhrd61lJuTedDreWp4Ykna/uHhodlO71/ M+HQjuZI5kTW7JA91BXRMIQgDaV1fWOg6tIjYx3sLnu5gGiwWQl1gN97nIMED6Gu4GebxuQoCy JVvc+yIQ584jtuY8vHRbgGulynbLLZI8zFBzod06UtE7BkB0yj4g4iLDsKGiNSqyTRU8cHQm4D MwBObbqGV6i1SY2FsvagwNMUt39jGDqrDppj6gMO32cokRzgV867gNnBUd6IfLhIYsPGYqKi2f RFEmMlPc5NH4FShWnHsEDwgr1+5AIaSZdSGNlZcOBFJZjg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ALUhlxESjjjPtDfJPu5g16IXDxXPs6M2JYNHpl/R1RE=; b=LiTh2tl10U+tR3ke3YfA3BS8KQ xvtj/VNEFCb08jM7rzR5UdE4tv4voPKrqqvYxK4C1bFeg6kchvVjebMPli2+OAP8MOHm3sUcBiQOO rjxHixaRjlX5gpSHBlNlmKniTKUbSUndr6VqtBiKUm0W6qnOZDvOO0SRQMYPZTsnRBQi/hpOaVczt FByM90bLsxBQ3UrXMOOrqVJK6FZrv/yRDiEhxBH5jkLdTH0g0laDW6qWItTBKY/HdJ7EJybzfxYLs YS7A2GxRAWcMJ8eRJJIRxDTvtH9ha4ZdhAWE/hU3tu8Xkp8M7V+ikhL7HwX4QnOtAmbLeP9WODYzd Ha2dOAFA==; Received: by zero.zsh.org with local id 1osJq2-000BY1-Rq; Tue, 08 Nov 2022 08:20:06 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f178.google.com) smtp.remote-ip=209.85.219.178; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-yb1-f178.google.com ([209.85.219.178]:43552) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1osJpG-000ApT-Gm; Tue, 08 Nov 2022 08:19:19 +0000 Received: by mail-yb1-f178.google.com with SMTP id y186so11857777yby.10 for ; Tue, 08 Nov 2022 00:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ALUhlxESjjjPtDfJPu5g16IXDxXPs6M2JYNHpl/R1RE=; b=BhmNFkvj1OEZIHPajrmykwkFHGzc8qqXJQMrjYXwVsY4ctrWmAEcxpUZkqc0ft7Vmq H8DlCUDXuYCR8eKEdZNFVYq+sOD5+IUFKTLoi+235vOqq3DHcC1QIhjXvgwz5YdFVIfR SINRBaFehuqcQjzr1CqnnP/7SrqOpEvoqBxFnjvN4V0r+O6GlocMG0wYTAEE8yA/XYJH 5LBR9WltebjBnFE5FpwiuKp29DKEzNpGFZnxm4PPdrM7u2s0tV59JMod+djuPgehrtmZ E39xQALA4Jlct1HKkZRC2wFv17SbCIQe9TJWZ8i31Q2kMUj73T9P6TN42nTpsUxl7jpv X6gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ALUhlxESjjjPtDfJPu5g16IXDxXPs6M2JYNHpl/R1RE=; b=QeNiI6J2ORVCFsWyxfaQTBC7ZmfhH75husPSj2CYUg7+ksLPmuAulxbZKB1hihZWMj sOC6bLdvE7/VthVxJUXEUZ+Najlskc9ab+LlTe0z5MTA9+CAqVifybR3WC48BfqBDYaA l5tsRa+T8IUI1YeqQYrx3moyK1+c7XcqF1Z5vGvvMYa/eSqmEVpgxrhbANK4p1u0vkgq BjCJG7PfcFt829hbsXFoWEF7spIItj5ZmLZSMCSMcbJKgXT+vREAnLpGLJ8S63XDU/mA /Zv7yZuFzgebmMPpT+wuHZr5EZ8YXr735dKNYC/PbMhRQpmG1nBd0TFFu4uqwk1Yg37U WNbw== X-Gm-Message-State: ANoB5pkuOcc32Yu3eLnioX2PpILxfKwPA1dcVtEt6Knpyba395jNcxrk PwJ7pJmdcvOWnYMaDN+IhFoLBcoSbHjFIpoeYm8= X-Google-Smtp-Source: AA0mqf6MAAgUnx2IJqXi+rXgLrvGRla+CZ9FsZ60UUe3X3a6jA8Tlqmdjq+NWlEhclfmtj/W59Wp+xioa+gs5mkmFP8= X-Received: by 2002:a25:d655:0:b0:6d3:7c5a:9d39 with SMTP id n82-20020a25d655000000b006d37c5a9d39mr21070479ybg.175.1667895557130; Tue, 08 Nov 2022 00:19:17 -0800 (PST) MIME-Version: 1.0 References: <9bc02014-76ca-b2c0-5f7c-284b90884225@eastlink.ca> <15a3af0a-87ad-49f8-ab9f-baa240e205f6@app.fastmail.com> <29b06e8a-e58a-91c6-985d-64020727d603@eastlink.ca> In-Reply-To: <29b06e8a-e58a-91c6-985d-64020727d603@eastlink.ca> From: Roman Perepelitsa Date: Tue, 8 Nov 2022 09:19:04 +0100 Message-ID: Subject: Re: [[ 'abcde' =~ (#i)Bcd ]] To: Ray Andrews Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 28337 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Nov 8, 2022 at 3:06 AM Ray Andrews wrote: > > > On 2022-11-07 13:50, Lawrence Vel=C3=A1zquez 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=3D$( basename $cc[$aa] 2> /dev/null ) There is a zsh way for this: local var=3D${cc[$aa]:t} "t" is short for tail. There is also "h" for head. > if [[ "$scope_msg" =3D 'BROAD' && $vvar =3D (#i)*$filter* ]]; then > elif [[ "$scope_msg" =3D 'Case INsensitive TAME' && $vvar:u =3D $filter:u > ]]; then > elif [[ "$scope_msg" =3D 'Case Sensitive WILD' && $vvar =3D~ $filter ]]; = then > elif [[ "$scope_msg" =3D 'EXACT' && $vvar =3D $filter ]]; then > else cc[$aa]=3D > 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 =3D=3D $~filter ]] Or, if you want to always perform a partial match: [[ $vvar =3D=3D *$~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 =3D=3D $~pattern ]] # case sensitive, full [[ $data =3D=3D (#i)$~pattern ]] # case insensitive, full [[ $data =3D=3D *$~pattern* ]] # case sensitive, partial [[ $data =3D=3D (#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.