|
2026-10-13
| ||
| 12:19 | • Closed ticket [471101ffff]: RE \A and ^ don't replace the same plus 10 o... artifact: d3c7262c60 user: jan.nijtmans | |
| 09:22 | Fix [471101]: regexp/regsub -all restarted matching on the substring after the previous match check-in: 481d6af9cd user: jan.nijtmans tags: core-8-6-branch | |
|
2026-10-12
| ||
| 11:34 | Fix [471101]: regexp/regsub -all restarted matching on the substring after the previous match check-in: d7f3dbef18 user: jan.nijtmans tags: core-9-0-branch | |
|
2026-10-11
| ||
| 20:17 | Fix [471101]: regexp/regsub -all restarted matching on the substring after the previous match check-in: d2a1819076 user: jan.nijtmans tags: trunk, main | |
| 20:06 | • Closed ticket [884d0ac78c]: Unexpected string-start constraint match in middle o... artifact: 749e60014c user: jan.nijtmans | |
| 08:21 | • Ticket [b73f129696] regexp -all misses an empty match at the end of the string</... artifact: 4a617ea2dc user: serhiy.storchaka | |
|
2026-10-10
| ||
| 17:51 | • Ticket [884d0ac78c] Unexpected string-start constraint match in middle of string... artifact: 78b694ae93 user: serhiy.storchaka | |
| 17:51 | • Ticket [471101ffff] RE \A and ^ don't replace the same status still Open... artifact: 17e1a5f661 user: serhiy.storchaka | |
| 17:41 | Fix [471101ffff] and [884d0ac78c]: regexp/regsub -all restarted matching on the substring after the ... closed check-in: 16686eeb78 user: serhiy.storchaka tags: regexp-all-search-start | |
|
2002-01-15
| ||
| 20:22 | • Ticket [471101ffff] RE \A and ^ don't replace the same status still Open... artifact: 657cfc5cc4 user: dgp | |
|
2001-10-15
| ||
| 03:19 | • Ticket [471101ffff]: 4 changes artifact: 5ded79ac93 user: hobbs | |
|
2001-10-14
| ||
| 20:02 | • New ticket [471101ffff]. artifact: bf57207e52 user: hobbs | |
RE \A and ^ don't replace the same
When no options are specified, \A and ^ should be the
same, but they don't seem to behave the same:
(hobbs) 79 % regsub -all {\Aa} {aabbcc} {b} r
2
(hobbs) 80 % set r
bbbbcc
(hobbs) 81 % regsub -all {^a} {aabbcc} {b} r
1
(hobbs) 82 % set r
babbcc
whereas \Z seems OK:
(hobbs) 83 % regsub -all {(\Aa|c\Z)} {aabbcc} {b} r
3
(hobbs) 84 % set r
bbbbcb
(hobbs) 85 % regsub -all {(^a|c$)} {aabbcc} {b} r
2
(hobbs) 86 % set r
babbcb
749e60014cClosed ticket [884d0ac78c]: Unexpected string-start constraint match in middle of string after newline plus 7 other changes ticket2026-10-11 20:06:594a617ea2dcTicket [b73f129696] regexp -all misses an empty match at the end of the string status still Open with 3 other changes ticket2026-10-11 08:21:4478b694ae93Ticket [884d0ac78c] Unexpected string-start constraint match in middle of string after newline status still Open with 3 other changes ticket2026-10-10 17:51:5116686eeb78Fix [471101ffff] and [884d0ac78c]: regexp/regsub -all restarted matching on the substring after the previous match, so \A, ^ (without -lineanchor) and word constraints matched again there. Search from the current offset in the whole string instead. New tests regexp-29.*; regexp-16.4 updated. check-in2026-10-10 17:41:55
Logged In: YES user_id=72656 This is actually ... correct. The problem is with the handling of offsets, and is indicated by the docs for regsub -start (which just allows the user to set the offset). -start index Specifies a character index offset into the string to start matching the regular expression at. When using this switch, `^' will not match the beginning of the line, and \A will still match the start of the string at index. If -indices is specified, the indices will be indexed starting from the absolute beginning of the input string. index will be constrained to the bounds of the input string. This result is actually the same for 8.2. I'm not sure that this is a great feature, but I think the only way to get around it is to get into the guts of the RE.
Still the same in 8.6, 9.0 and 9.1. With -all, regexp and regsub restarted matching on the substring after the previous match, so \A matched again at each restart point; ^ was only protected by TCL_REG_NOTBOL. All other engines (PCRE, Perl, Python, Java, Ruby, and PostgreSQL, whose engine is derived from Tcl's) match \A only once.
Word constraints are affected the same way, since they could not see the character before the restart point: regexp -all -inline {\m\w} "ab cd" returns a b c d instead of a c, and \y matches between any two word characters.
Proposed fix in branch regexp-all-search-start: successive matches are searched from the current offset in the whole string, so \A matches only at the start (or at the -start index) and word constraints see the previous character. Tests regexp-29.*. Test regexp-16.4, which expected the old behaviour, is updated. This changes behaviour, so it is proposed for the next feature release, not for backporting. Also fixes [884d0ac78c].
Fixed in [trunk], core-9-0-branch and core-8-6-branch
Many thanks!