Skip to content
Tcl Source Code History Of Ticket 446565
Login

History Of Ticket 446565

Artifacts Associated With Ticket 446565

  1. Ticket change [ab89b8ce7e] (rid 101132) by nobody on 2001-07-31 21:29:19:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      See attached archive (sample script with text data).
      If you can't see attached file, look at 
      http://ifast.narod.ru/files/regbug.zip
      
    4. foundin initialized to: "obsolete: 8.3.2"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "18. Commands M-Z"
    10. title initialized to: "Interpreter hungs on regexp"
    11. type initialized to: "Bug"
  2. Ticket change [d4b608f283] (rid 123495) by msofer on 2001-08-01 04:39:34:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      Bug confirmed: tclsh seems to get in an infinite loop.
      Attaching the file now
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. subsystem changed to: "43. Regexp"
    5. username: "msofer"
  3. Ticket change [ef03def9e5] (rid 108920) by msofer on 2001-08-01 04:39:35:

    1. icomment:
      
      
      File Added - 9093: regbug.zip
      
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  4. Add attachment "regbug.zip" [b4509a2487] (rid 125008) by msofer on 2001-08-01 04:39:35.

  5. Ticket change [7a31ab2043] (rid 90268) by msofer on 2001-08-01 05:42:46:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      The regular expression 
       
      {<script(.(?!</script>))*?(doubleclick|flycast|burstnet|spylog)+?.*?</script>}
      is invalid: it contains a constraint (the lookahead)
      followed by a quantifier, which is expressly forbidden in
      the man page for re_syntax.
      
      I think the author actually wanted something like
       {<script
      (?=.*</script>).*?(doubleclick|flycast|burstnet|spylog).*?</script>}
      which runs OK (albeit slowly; there is probably a better way
      to express this).
      
      OTOH, the regexp engine should complain about the bad syntax
      and return an error, instead of getting into an infinite
      loop. 
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  6. Ticket change [b5038eceae] (rid 125161) by kofeinik on 2001-08-04 04:28:19:

    1. icomment:
      Logged In: YES 
      user_id=286083
      
      >The regular expression 
      >{<script(.(?!</script>))*?
      >(doubleclick|flycast|burstnet|spylog)+?.*?</script>}
      >is invalid: it contains a constraint (the lookahead)
      >followed by a quantifier, which is expressly forbidden in
      >the man page for re_syntax.
      
      You aren't right. If you follow lookahead constraint 
      directly (NB!) with quantifier, interpreter reports an 
      error. And my construction works fine (interpreter doesn't 
      report any error), because lookahead atom doesn't follow 
      any quantifier. But works quickly only on small buffer.
      Also, if you wait a long-long time (you can decrease text 
      size between <script> and </script> in example), 
      interpreter un-hungs, and return correct result.
      
      
      >I think the author actually wanted something like
      >{<script(?=.*</script>).*?
      >(doubleclick|flycast|burstnet|spylog).*?&lt;/script>}
      >which runs OK (albeit slowly; there is probably a 
      >better way to express this).
      
      You aren't right again. :)
      Try:
      # my expression
      set my {<script(.(?!</script>))*?(123)+?.*?</script>}
      # your expression
      set mo {<script(?=.*</script>).*?(123).*?</script>}
      # sample text
      set text {<script> 123 </script> <script> 345 </script> 
      <script> 123 </script>}
      
      # Correct result
      regsub -all $my $text --- res
      2
      set res
      --- <script> 345 </script> ---
      
      # Not correct result: 
      regsub -all $mo $text --- res
      2
      set res
      --- ---
      
      Btw, if you know, how to get first result without using of 
      constraint lookahead with non-greedy quantifier, let me 
      know. :)
      
      >OTOH, the regexp engine should complain about the 
      >bad syntax
      >and return an error, instead of getting into an infinite
      >loop. 
      
      IMHO, itsn't infinite loop, but only very slow work with 
      lookahead constraints.
      
      
      
    2. login: "kofeinik"
    3. mimetype: "text/plain"
    4. username: "kofeinik"
  7. Ticket change [8075ef8877] (rid 116868) by msofer on 2001-08-07 01:12:51:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      Indeed, I am both wrong and sorry.
      
      The "capturing parens" are very costly in this case;
      replacing them with the "non-capturing" variant produces the
      desired result. The regex becomes then
      
      {<script(?:.(?!</script>))*?(?:doubleclick|flycast|burstnet|spylog)+?.*?</script>}
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. username: "msofer"
  8. Ticket change [fda98b6d6b] (rid 108445) by msofer on 2001-08-13 20:04:41:

    1. foundin changed to: "None"
  9. Ticket change [fcc52aa56c] (rid 108298) by msofer on 2001-08-13 20:04:43:

    1. icomment:
      Logged In: YES 
      user_id=148712
      
      The originally submitted script does perform as intended,
      only very slowly. The use of non-capturing parens solves the
      issue.
      
      It now seems clear that the bug is really a performance and
      not a functionality issue. 
      
      I am therefore changing the summary description and reducing
      the priority.
      
      
      
      
    2. login: "msofer"
    3. mimetype: "text/plain"
    4. priority changed to: "3 Low"
    5. title changed to: "Capturing parens are very slow"
    6. username: "msofer"
  10. Ticket change [358036df2c] (rid 106947) by dgp on 2003-11-13 05:18:08:

    1. assignee changed to: "pvgoran"
  11. Ticket change [6097638f5d] (rid 116026) by dgp on 2003-11-13 08:15:19:

    1. foundin changed to: "obsolete: 8.4.4"
  12. Ticket change [dd629d3c95] (rid 257557) by serhiy.storchaka on 2026-10-11 07:06:58:

    1. foundin changed to: "8.6.18, 9.0.5, 9.1.0"
    2. icomment:
      Still the same in 8.6, 9.0 and 9.1. Finding the submatch boundaries of this RE is much more expensive than finding the match, and <tt>regsub</tt> always asked the regexp engine for 10 submatches, even when the replacement string does not refer to any of them.
      
      Proposed fix in branch [/timeline?r=regsub-needed-submatches|regsub-needed-submatches]: <tt>regsub</tt> asks only for the submatches that the replacement string refers to, so the attached example now takes milliseconds instead of a second. A replacement with <tt>\1</tt> or <tt>\2</tt>, and <tt>regexp</tt> with submatch variables, are still slow with such REs. Tests regexp-31.1 to 31.5.
      
    3. login: "serhiy.storchaka"
    4. mimetype: "text/x-fossil-wiki"