|
2026-11-14
| ||
| 16:02 | Fix [41bc9a] and [446565]: regsub -command panics with more than 9 capturing groups/regsub always as... check-in: 92bd7a0578 user: jan.nijtmans tags: core-9-0-branch | |
|
2026-10-16
| ||
| 11:43 | Fix [446565]: regsub always asked the regexp engine for 10 submatches check-in: 9b818c9f14 user: jan.nijtmans tags: trunk, main | |
|
2026-10-11
| ||
| 07:06 | • Ticket [446565ffff] Capturing parens are very slow status still Open with 4 ... artifact: dd629d3c95 user: serhiy.storchaka | |
| 06:55 | Fix [446565]: regsub always asked the regexp engine for 10 submatches, which can be far more expensi... closed check-in: 5580370a8f user: serhiy.storchaka tags: regsub-needed-submatches | |
|
2003-11-13
| ||
| 08:15 | • Ticket [446565ffff] Capturing parens are very slow status still Open with 1 ... artifact: 6097638f5d user: dgp | |
| 05:18 | • Ticket [446565ffff]: 1 change artifact: 358036df2c user: dgp | |
|
2001-08-13
| ||
| 20:04 | • Ticket [446565ffff]: 6 changes artifact: fcc52aa56c user: msofer | |
| 20:04 | • Ticket [446565ffff]: 1 change artifact: fda98b6d6b user: msofer | |
|
2001-08-07
| ||
| 01:12 | • Ticket [446565ffff]: 4 changes artifact: 8075ef8877 user: msofer | |
|
2001-08-04
| ||
| 04:28 | • Ticket [446565ffff]: 4 changes artifact: b5038eceae user: kofeinik | |
|
2001-08-01
| ||
| 05:42 | • Ticket [446565ffff]: 4 changes artifact: 7a31ab2043 user: msofer | |
| 04:39 | • Ticket [446565ffff]: 4 changes artifact: ef03def9e5 user: msofer | |
| 04:39 | • Add attachment regbug.zip to ticket [446565ffff] artifact: b4509a2487 user: msofer | |
| 04:39 | • Ticket [446565ffff] Interpreter hungs on regexp status still Open with 5 oth... artifact: d4b608f283 user: msofer | |
|
2001-07-31
| ||
| 21:29 | • New ticket [446565ffff]. artifact: ab89b8ce7e user: nobody | |
Capturing parens are very slow
Open446565ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 53 days ago
Descriptionplain2001-07-31 21:29:19
See attached archive (sample script with text data). If you can't see attached file, look at http://ifast.narod.ru/files/regbug.zip
msoferplain2001-08-01 04:39:34
Logged In: YES user_id=148712 Bug confirmed: tclsh seems to get in an infinite loop. Attaching the file now
msoferplain2001-08-01 04:39:35
File Added - 9093: regbug.zip
msoferplain2001-08-01 05:42:46
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.
kofeinikplain2001-08-04 04:28:19
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).*?</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.
msoferplain2001-08-07 01:12:51
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>}
msofer Ticket [446565ffff]: 1 change
[History diff]2001-08-13 20:04:41
msoferplain2001-08-13 20:04:43
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.
dgp Ticket [446565ffff]: 1 change
[History diff]2003-11-13 05:18:08
dgp Ticket [446565ffff]: 1 change
[History diff]2003-11-13 08:15:19
serhiy.storchakawiki2026-10-11 07:06:58
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 regsub always asked the regexp engine for 10 submatches, even when the replacement string does not refer to any of them.
Proposed fix in branch regsub-needed-submatches: regsub 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 \1 or \2, and regexp with submatch variables, are still slow with such REs. Tests regexp-31.1 to 31.5.
Log in (anonymous is fine) to add a comment.
Attachments:
- regbug.zip [download] added by msofer on 2001-08-01 04:39:35. [details]