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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29389 invoked from network); 9 Dec 2023 05:15:00 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Dec 2023 05:15:00 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1702098901; b=P47lgThfFenB7qO2lGoycl6Aay8tYNEMDOKcUIlSm7SOGAYoU0goUOFf10/al2u1irSNalOQx1 QMhwrPWyWDEgfyEX8bIgAE4TDVGe5kDoPKJDKyHJlMFiMQmGlqc00D26rCwPCTuGoxwsmVFLOG CoHpcm3cynIPLfbXnhldgTyc62Qs/ZukSSZNiQ51g3rbMBDnZcKAKx5+WFJBwxRu54rgcgRFwl pTDqzgHb6BmrQ8r0wMjN2q3zjyLrAtwQC8iCbLSxkf0UnkgwWGbaOhGwBT99PXRQIsSlDYJOrG EQOnoFiJzyK+aZhyDZBSFXAkso5p5hLmU9c/o8uyj/+Yjw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wm1-f42.google.com) smtp.remote-ip=209.85.128.42; dkim=pass header.d=gmail.com header.s=20230601 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=1702098901; bh=VXWoyyeT7cpHfL2IqcNKh2txrnvv8d7348jOIRr7YrA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:Date:Message-ID:Subject:MIME-Version: Content-Transfer-Encoding:Content-Type:From:DKIM-Signature:DKIM-Signature; b=b8ZledPnoVUS1fpKzzf5HhOm/O+lvn8s5RmBrI8pCwp1YDCNumt/hMg9anQD4n3jtnoV+aJYoG JHCKXo2XbDDbVwg4gDW5Rlksk+unFnHWjRwBUCzsbk4QgUkwkTT8sI30/x+cjdCNikjjWnx1LH sQKePyHTX+k5XT7zi22bzw6ONorpGI4XTd9g1wOWvIlCUKIkrHZNIL8dWVN/PBgrxZ8S5sfeOR G4yTp3Xuh2B735OQ/cg/gRnk0aA8Oc9T/GXYH4mLDA/iT6laA3aeR/c6dHoKP07c+1gdqHqAzQ rDK/NmzefXoGXaIxQHh5TV/PeBHABqN8o1NYVK0MRAZFpw==; 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:To:Date:Message-Id:Subject: Mime-Version:Content-Transfer-Encoding:Content-Type:From:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=0Gs8YJxLkwdmoll7AgZ3ZxJVQIor9wM9CKY/mtFtvIc=; b=NwuqkNQKuEoJr99IVea95msnxx 0z2ZDJKuWAKLFjIv40tPUg4R4tlqRzNmMjunssvoj98DK4Asfqb3NhMUAbUs1ySs1E1bnSoOWG08G 7V2fYlpvkCsKvdh/PJ74w2GQZp/9qpsB3SX5RffJR5R50vKvRrv+hWOenqN6ryy9bLxUfKX+Z7iR3 LVO1oI/IolAbfHltHUaSywwKYdc/UlyPQ05OFxPt/ew9Y/tT6I5rJwATK/BYETGdCAWa/eI+mayq/ 7xw9SDxi5hFdUrnX4OvnuVDkANAAVu6TJcv43adUb6kNizyTXOKy+EpOMINZLJ/fcUH0EqIxCDjUk akz79uYQ==; Received: by zero.zsh.org with local id 1rBpg4-000EQL-5S; Sat, 09 Dec 2023 05:15:00 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wm1-f42.google.com) smtp.remote-ip=209.85.128.42; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wm1-f42.google.com ([209.85.128.42]:47469) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rBpfQ-000E7q-Cv; Sat, 09 Dec 2023 05:14:22 +0000 Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40c32df9174so15827285e9.3 for ; Fri, 08 Dec 2023 21:14:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702098860; x=1702703660; darn=zsh.org; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=0Gs8YJxLkwdmoll7AgZ3ZxJVQIor9wM9CKY/mtFtvIc=; b=DlFJJSDbpVo3jkjhS21FLDjgc+N/RKY0tjuzHl6MzGt0JRrVBVHlHWAzlyBOdETEtP TpIwnvYMV2wixMjIIVR36LUlBNsmCdYE764UwniCs9tXtDUU3GCaGMpoH0S5KI/FSvK2 fPtdLtIrkVzfmGBtgE0uiOgsDhlXX/yvUuIiQWekC25J96NHRqIi4YNelPJE0GvbsfBa P0Fn2m/g0FpF6GzvJsLk/8d6+048EV/hnJ7yYTzTyBhq2cNTCR6xQj5dgRqCLmby3Ygf hiPiI+g4kunEHJEhTUjTUkpz1gMTBcczXB7mDDQIK27no/FvHoV5GfWy8PWhQvIlHsZq sEzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702098860; x=1702703660; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0Gs8YJxLkwdmoll7AgZ3ZxJVQIor9wM9CKY/mtFtvIc=; b=pO8+lK0yIRgOAxiRNZ0yqC89na3P5x153qShJLQzTtA2S21Kb8VWSrhLx5BP/QXbUT 1TYxRC8+NRyCTh1dpu/TzWOsqGLNbyjjFz/izwido2GqtH9EMS2KHqljmvjR4A0revNN wqsZeS7+6r4lH2WKkve7uZUf6mFrFvmCAskxf1E/HRKplQhn5coCn7e9P8TkjKJDTvkk D1iYfGLxFA0VOWMChwy1TyG6DeA/6WlHXSFm+DEs7VQVYC3jJ5/EC1b/J/E+dyLLUa3w 0nVM7XCfY04SSqdCpRnJnT4Wu9YdzoMej4RLQoifBh4xwTT4epB0YUHrPuNFWWdhZdrF njbw== X-Gm-Message-State: AOJu0YzZJtFdlj+iTkr9iBVtZHoGZuxZHy0lm+YBMNjri0qum4dXW5Nx +KbRDq3N8rJ/VtfkXjER8NonJQZUDSw= X-Google-Smtp-Source: AGHT+IETE+VamRaHMv21z9qzY/Rt5xVDPmup4IsG4a4w257FFW73nb2tKL5f4MVjxM+JN69y87TTwg== X-Received: by 2002:a05:600c:331c:b0:40b:5e1e:fb8c with SMTP id q28-20020a05600c331c00b0040b5e1efb8cmr326704wmp.65.1702098859655; Fri, 08 Dec 2023 21:14:19 -0800 (PST) Received: from [192.168.0.4] (parableuk.force9.co.uk. [81.174.154.32]) by smtp.gmail.com with ESMTPSA id fl9-20020a05600c0b8900b0040b43da0bbasm4922764wmb.30.2023.12.08.21.14.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Dec 2023 21:14:19 -0800 (PST) From: chris0e3@gmail.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: =?utf-8?Q?=5BBUG=5D_=60=24match=60_is_haunting_my_regex=E2=80=99s?= =?utf-8?Q?_trailing=2C_optional=2C_capture?= Message-Id: Date: Sat, 9 Dec 2023 05:14:18 +0000 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3273) X-Seq: 52386 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Hello, I=E2=80=99m using a custom built zsh 5.9 & PCRE 8.45 on macOS. I=E2=80=99m seeing unexpected values in `$match` after a successful = match. What is the expected output of: ``` setopt rematch_pcre [[ 'REQUIRE. OPT' =3D~ 'REQUIRE.(\s*OPT)?' ]] && printf '\tA. = =E2=80=B9%s=E2=80=BA\n' $match [[ 'REQUIRE.' =3D~ 'REQUIRE.(\s*OPT)?' ]] && printf '\tB. = =E2=80=B9%s=E2=80=BA\n' $match ``` I had expected: ``` A. =E2=80=B9 OPT=E2=80=BA B. =E2=80=B9=E2=80=BA ``` But I get: ``` A. =E2=80=B9 OPT=E2=80=BA B. =E2=80=B9 OPT=E2=80=BA ``` Reversing the order of the tests (& executing them in a new Terminal = window) produces expected/different results. [Though executing in a = sub-shell appears to inherit the previous value of `$match`. Is that = expected?] So this is probably just due to `$match` initially being = empty. However, changing the regex to 'REQUIRE.(\s*OPT)?(.*)' or = '(REQUIRE).(\s*OPT)?' produces expected results. It looks like: if there is a match, but no captures are matched then = `$match` is not cleared. However, I think it should be cleared. The = zsh manual =C2=A722.23 appears to imply what I contend. [If I read it = correctly.] Based on my hypothesis I wrote this (simplification): ``` setopt rematch_pcre; match=3DRUBBISH [[ A =3D~ 'A|(B)' ]] && printf '\ta. =E2=80=B9%s=E2=80=BA\n' $match [[ B =3D~ '(A)|B' ]] && printf '\tb. =E2=80=B9%s=E2=80=BA\n' $match ``` I would expect: ``` a. =E2=80=B9=E2=80=BA b. =E2=80=B9=E2=80=BA ``` But I get: ``` a. =E2=80=B9RUBBISH=E2=80=BA b. =E2=80=B9RUBBISH=E2=80=BA ``` [But changing the regexes to 'A()|(B)' & '(A)|B()' produces the expected = results.] So. Am I right? And is it possible to fix zsh? Or am I wrong? Thanks, CHRIS