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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17260 invoked from network); 8 Nov 2022 17:41:24 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Nov 2022 17:41:24 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667929285; b=XtfIckjI1C4DEeOFumsuwkwuF7YnpPeADO8XRhJMJ8f8aS5UvX7qCfwShOo60uvQf/5gpO4LrP Q04Usg9hN8e6quQLDj35yBAm01YbcJRfL6123Ul5E3tcXyEW8Ihr0rBot0+dQ0FZVs5GLL8S+f d234fn0qiYe6L51qkYpmiGfHYo8BmujUJ6fIzMvuF6hwV2KT2TmgmNn3wINtL6tTTD/dq7zdEy F/8qT3bfMhCxwS2wyzjNZUXBAl79xJHTf1Ms9UJVII2/rdSc1at/TmQQNAG6LIN+Vi5RvMnnrX CUJu4Ze+fBDUp8j8xT5/AVXc7BEqExA/V9JvgSyJNAQP2A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mx.spodhuis.org) smtp.remote-ip=94.142.241.89; dkim=pass header.d=spodhuis.org header.s=d202208e2 header.a=ed25519-sha256; dkim=pass header.d=spodhuis.org header.s=d202208 header.a=rsa-sha256; dmarc=pass header.from=spodhuis.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1667929285; bh=NuplwvSuQ9DIct0JCQrefdf0t7HkTi+6+OyUFcraI/g=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=PM8tnoQGmFIAmksK06LJN2cbR4gt8YhFZGgB1AU8TUFvl6RDH2zx7/aOlqmCtA6//FpTytV2uQ dwyuH28cxRTLgp4+ZS112qNQcTmS7p7oysYfzHU5TyPnIpDU6vs66Ae/bqMaeKLjKZpaFDPdFR qHVD4RLamks06HvgBdhGhUmCDTAMWgzKxkSqMHBi8Pn/tAmHgfk5m5Z2EBM/gM2L5J4Op7YTop ypaJb3xR41PrFq6sfOExyNXqdQgIDGAcEVKgkd+meMRl57FAmvmxNi6Y5Sez0kUR/F9FxyeOzt 4OG1Szw+X+QDexXXIC7Rqh0wmfvamo7NNFUlVZ7QPi6LhA==; 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:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=BMysSrXs/N2tWdmAeU9M4tsFxilOHAtapTcq5EdAceY=; b=PtyIUmdO5Jy31uElHu5IaB3WiM RisD/g3C6CJUcIn9aD9EhqyZJOYdpztMIZmNiX6Vd/9PuerCDCFLGzrDiZd3zoBav8PxVuXUwIfDz H6iK/WxYA78RBC1qsOFL9ACxggOtfF+LMYb7Ov9+ydgmpaiZpiLSzmCdC/CDQg1kh3EBIQtIdqVKx iLUwu1ZLQCx3a2ISvNPdeg2gB3pxEpcJoBnjxswGqPXd2GArAx0MSIW0ExJsXrf+9hoAp+xn18VRi E+VUUnuPZu5XSKh+6JxTP8H1uOJTh1GLOPZA9pesKruAgP0KtTmKD9b9GWfHz/4bWjqCPqj5x43PH Ks84brLQ==; Received: by zero.zsh.org with local id 1osSbE-0005CY-5D; Tue, 08 Nov 2022 17:41:24 +0000 Authentication-Results: zsh.org; iprev=pass (mx.spodhuis.org) smtp.remote-ip=94.142.241.89; dkim=pass header.d=spodhuis.org header.s=d202208e2 header.a=ed25519-sha256; dkim=pass header.d=spodhuis.org header.s=d202208 header.a=rsa-sha256; dmarc=pass header.from=spodhuis.org; arc=none Received: from mx.spodhuis.org ([94.142.241.89]:43447) (DNSSEC AD) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1osSaM-0004Nw-1g; Tue, 08 Nov 2022 17:40:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d202208; h=OpenPGP:In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date:From: Reply-To:Subject:Date:To:Cc:Content-ID:Content-Description:OpenPGP: Organization:Auto-Submitted; bh=BMysSrXs/N2tWdmAeU9M4tsFxilOHAtapTcq5EdAceY=; t=1667929229; x=1669138829; b=CJlg+2zrg0o348NgUlvxQ+wVAZZeDDW7UBZ6oO7dFlvxO4p 2NlBfZNvqthkbdIr0jIreXfKFWha708NKBCU8e/HrRNq/sLhEuvJ9gGmC4lALfmnQ41tpKjNyVpEF ME169N9comufkdENrXL/IRArcZk9s+/B+4z1f6WlxR+QKPhdmLvkpxRQCttnoCnNlpXEliC3dayWZ uR4MwpfKXTblz2cSEE8/ySHNxtLhqOl2JQeZkcdB9yoNonoFJ9wuEev2HkdSgVRAAnhdwmpezZsJn cmwLMEf9omGeFrMjm/1/mV0OVnS4DbSGbXC1CVsftBTobbw4/06Z4+GKCu1rRB8Q==; DKIM-Signature: v=1; a=ed25519-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d202208e2; h=OpenPGP:In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date:From: Reply-To:Subject:Date:To:Cc:Content-ID:Content-Description:OpenPGP: Organization:Auto-Submitted; bh=BMysSrXs/N2tWdmAeU9M4tsFxilOHAtapTcq5EdAceY=; t=1667929230; x=1669138830; b=8OJx6gtq1P7J17GDeX2jnn6mP8JbHvBsfLAipORyOvMa8VU eo6D98HuBrx9ZH2H0TMWl1skWMtya/LNvzeyWDQ==; Received: from authenticated user by smtp.spodhuis.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1osSaL-0004NW-6K; Tue, 08 Nov 2022 17:40:29 +0000 Date: Tue, 8 Nov 2022 12:40:26 -0500 From: Phil Pennock To: zsh-users@zsh.org Subject: Re: [[ 'abcde' =~ (#i)Bcd ]] Message-ID: References: <9bc02014-76ca-b2c0-5f7c-284b90884225@eastlink.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9bc02014-76ca-b2c0-5f7c-284b90884225@eastlink.ca> OpenPGP: url=https://www.security.spodhuis.org/PGP/keys/keys-2013rsa-2020cv25519.asc X-Seq: 28342 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 2022-11-07 at 13:10 -0800, Ray Andrews wrote: > [[ 'abcde' =~ 'bcd' ]] && echo match1 > [[ 'abcde' = (#i)ABcde ]] && echo match2 > [[ 'abcde' =~ (#i)Bcd ]] && echo match3 > [[ 'bcd' =~ 'abcde' ]] && echo match4 > > ... I get match 1 and match 2.  I  understand not getting match 4 because > '=~' is not bi-directional, the latter value must be a subset of the > former.  But why don't I get match 3? It seems to break no rules to make > 'Bcd' case insensitive and then find it within 'abcde'.  Is there a > workaround? * = : equivalent to "==", string comparison with globs supported * =~ : regular expression match, syntax from Perl, used in bash * -regex-match : operator for very explicit regexp match * -pcre-match : operator for very explicit regexp match In zsh, = and == came first, then -pcre-match. The =~ operator from Perl was added to bash and I added support to zsh, and wrote the zsh/regex module so that _by default_ zsh would be compatible with bash. Using `setopt pcre_match` will switch =~ from bash-compatible to using PCRE, Perl Compatible Regular Expressions, so much closer to the original =~. The downside of PCRE in zsh is that for licensing reasons, not all distributions include it. Zsh itself is BSD-licensed, PCRE is not. If PCRE is available, then: [[ 'abcde' =~ (?i)Bcd ]] && echo match3 Use `man pcrepattern` and look at "INTERNAL OPTION SETTING" to see how (?something) turns on options, with 'i' being PCRE_CASELESS. This syntax matches Perl. If PCRE is not available, then you are stuck with ERE syntax (see `man 7 regex`) and you'll have to be a lot more explicit. So probably better to find ways to use zsh glob pattern matching instead of regular expressions. -Phil