Skip to content
Tcl Source Code History Of Ticket fbc56b259e
Login

History Of Ticket fbc56b259e

Artifacts Associated With Ticket fbc56b259e

  1. Ticket change [8dbe346221] (rid 239837) by david-a-wheeler on 2025-05-05 18:34:36:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      I propose that \z be accepted in regular expressions as a synonym for \Z.
      Below is a rationale, the one-line patch that implements it, and a
      few more patch lines to modify the documentation.
      
      First, the rationale.
      
      A common use for regexes in security is to check inputs,
      which needs anchors for "beginning of string" and "end of string"
      (regardless of multi-line mode, etc.)..
      Different regex engines notate this differently, making guidance complicated.
      See: https://best.openssf.org/Correctly-Using-Regular-Expressions.html
      
      People often copy regular expressions from one engine to another.
      46% of developers incorrectly believe that regexes are the same everywhere
      per Wang et al’s “An Empirical Study on Regular Expression Bugs” (2020).
      It's going to get *worse* with LLMs, which don't always note context.
      
      The good news is that there *is* a notation everyone can support: \A ... \z.
      This is supported by:
      Java, .NET/C#, Perl, PCRE, PHP (using PCRE), Ruby,
      RE2 which is widely used by Go, and Rust crate regex
      which is widely used by Rust.
      
      The phrase "\Z" cannot become a generally-agreed symbol for end-of-string,
      because it's already used for "optional newline followed by end of string" on
      many platforms, including Java, .NET/C#, Perl, PCRE , PHP (using PCRE),
      and Ruby. Citations:
      https://learn.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions#end-of-string-or-before-ending-newline-z
      https://www.pcre.org/original/doc/html/pcrepattern.html#SEC5
      https://ruby-doc.org/core-2.5.8/Regexp.html
      
      The Austin Group has decided to add \A and \z (not \Z) to
      POSIX EREs and encourage them for POSIX BREs:
      https://www.austingroupbugs.net/view.php?id=1919
      
      Python already supports \A; they've decided to add support for \z
      for "end-of-string" and are discussing deprecating \Z for end-of-string.
      https://github.com/python/cpython/issues/133306
      
      Anyway, I hope that \A ... \z would be supported here as well.
      It'd be nice to be able to say "this works practically everywhere"
      instead of the complicated explanations that must be done today.
      
      Thanks!
      
      
      diff --git a/generic/regc_lex.c b/generic/regc_lex.c
      index bf936ca607..cf791bacf1 100644
      --- a/generic/regc_lex.c
      +++ b/generic/regc_lex.c
      @@ -872,6 +872,7 @@ lexescape(
       	NOTE(REG_ULOCALE);
       	RETV(NWBDRY, 0);
       	break;
      +    case CHR('z'):
           case CHR('Z'):
       	RETV(SEND, 0);
       	break;
      diff --git a/doc/re_syntax.n b/doc/re_syntax.n
      index b2143493a1..c1c8971e53 100644
      --- a/doc/re_syntax.n
      +++ b/doc/re_syntax.n
      @@ -136,6 +136,7 @@ below).
       .PP
       The difference between string and line matching modes is immaterial
       when the string does not contain a newline character.  The \fB\eA\fR
      +and \fB\ez\fR and
       and \fB\eZ\fR constraint escapes have a similar purpose but are
       always constraints for the overall string.
       .PP
      @@ -452,6 +453,9 @@ matches only at the end of a word
       matches only at the beginning or end of a word
       .IP \fB\eY\fR 6
       matches only at a point that is not the beginning or end of a word
      +.IP \fB\ez\fR 6
      +matches only at the end of the string (see \fBMATCHING\fR, below, for
      +how this differs from
       .IP \fB\eZ\fR 6
       matches only at the end of the string (see \fBMATCHING\fR, below, for
       how this differs from
      @@ -707,7 +711,8 @@ expressions using \fB^\fR will never match the newline character (so
       that matches will never cross newlines unless the RE explicitly
       arranges it) and \fB^\fR and \fB$\fR will match the empty string after
       and before a newline respectively, in addition to matching at
      -beginning and end of string respectively. ARE \fB\eA\fR and \fB\eZ\fR
      +beginning and end of string respectively. ARE \fB\eA\fR and
      +\fB\ez\fR and \fB\eZ\fR
       continue to match beginning or end of string \fIonly\fR.
       .PP
       If partial newline-sensitive matching is specified, this affects
      
    5. is_private initialized to: "0"
    6. login: "david-a-wheeler"
    7. priority initialized to: "5 Medium"
    8. private_contact initialized to: "4142338a69292517b14056e8c2f582f9f21d882c"
    9. resolution initialized to: "None"
    10. severity initialized to: "Important"
    11. status initialized to: "Open"
    12. submitter initialized to: "david-a-wheeler"
    13. subsystem initialized to: "43. Regexp"
    14. title initialized to:
      Add support for \z in regex as end-of-string anchor
      
    15. type initialized to: "Patch"
  2. Ticket change [25ab20bab8] (rid 239880) by serhiy.storchaka on 2025-05-06 18:18:36:

    1. icomment:
      I should add that the reason why `\Z` was used for the "end of string" anchor in Python was a bug in early versions of PCRE (before PCRE 2.0). Perhaps the use of `\Z` in Tcl has the same history. Then this change can be considered a fix for a very old bug.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-markdown"
  3. Ticket change [c830ce6be9] (rid 239881) by david-a-wheeler on 2025-05-06 19:30:40:

    1. icomment:
      
      (Quick note: The proposal is simply to *add* functionality, so this is backwards-compatible with existing TCL programs.)
      
    2. login: "david-a-wheeler"
    3. mimetype: "text/plain"
  4. Ticket change [a8ad790c03] (rid 239887) by jan.nijtmans on 2025-05-07 13:37:24:

    1. icomment:
      I don't have a problem with this change. Pity that it didn't came in a few months earlier. I'll discuss it
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  5. Ticket change [f0ed1e392d] (rid 240064) by jan.nijtmans on 2025-05-14 10:59:10:

    1. icomment: "Put in a branch now: [31c03110d4deee2d]"
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  6. Ticket change [d5e8741c46] (rid 256763) by serhiy.storchaka on 2026-09-20 11:23:12:

    1. icomment:
      Status: Python 3.14 added <tt>\z</tt> as a synonym for <tt>\Z</tt> ([https://github.com/python/cpython/issues/133306|python/cpython#133306]) and its standard library now uses <tt>\z</tt>; the Austin Group accepted <tt>\A</tt> and <tt>\z</tt> for POSIX EREs. Tcl's <tt>\Z</tt> already has the <tt>\z</tt> semantics (it never matches before a trailing newline), so the synonym is exact.
      
      The branch [31c03110d4] merges cleanly onto the current main and passes the regexp tests. Two remarks before merging: the tests should add <tt>\z</tt> cases rather than replace the <tt>\Z</tt> ones (which lose coverage), and re_syntax.n should list <tt>\z</tt> among the constraint escapes (the <tt>.IP</tt> entry from the original patch), not only in the MATCHING section. Can this go into 9.1?
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  7. Ticket change [c04fdc7405] (rid 256776) by jan.nijtmans on 2026-09-21 07:33:40:

    1. assignee changed to: "jan.nijtmans"
    2. icomment:
      Thanks!  I totally forgot about this one.
      
      If there are no objections, I'll try to get it in Tcl 9.1.
      
      branch now update to trunk, and followed your suggestions on testcases and documentation!
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/plain"
  8. Ticket change [21cfcb7de0] (rid 256815) by jan.nijtmans on 2026-09-21 19:08:35:

    1. icomment:
      Merged to [0fb83e593fd88c32|trunk] now. Will be in Tcl 9.1
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  9. Ticket change [66c7cd1f1c] (rid 256816) by jan.nijtmans on 2026-09-21 19:12:10:

    1. closedate changed to: "2461305.3001203011"
    2. closer changed to: "jan.nijtmans"
    3. login: "jan.nijtmans"
    4. mimetype: "text/plain"
    5. resolution changed to: "Fixed"
    6. status changed to: "Closed"