|
2026-10-11
| ||
| 20:06 | • Closed ticket [884d0ac78c]: Unexpected string-start constraint match in middle o... artifact: 749e60014c user: jan.nijtmans | |
|
2026-10-10
| ||
| 17:51 | • Ticket [884d0ac78c]: 3 changes 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 | |
|
2021-02-20
| ||
| 21:37 | • Ticket [884d0ac78c] Unexpected string-start constraint match in middle of string... artifact: 232693a760 user: tgl | |
|
2017-12-28
| ||
| 12:47 | • Ticket [884d0ac78c]: 3 changes artifact: 5334e6a471 user: dkf | |
| 00:52 | • New ticket [884d0ac78c]. artifact: f14c2702b8 user: dkf | |
Unexpected string-start constraint match in middle of string after newline
Closed / Duplicate884d0ac78cbab248d054ec96d13c2a741bb0a94cCreated 9 years agoUpdated 52 days ago
Descriptionhtml2017-12-28 00:52:02
If you do:
regexp -all {^|\n} "foo\nbar"
then it returns 3. I'd expect that (perhaps) with the -line option, but in standard mode that is rather "surprising" as there is only one place where the string starts and only one newline character.
Referenced by2
17e1a5f661Ticket [471101ffff] RE \A and ^ don't replace the same 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
dkfhtml2017-12-28 12:47:54
A consequence of this issue is this:
% puts [regsub -all "^|\n" "foo\nbar" "\nXX"] XXfoo XX XXbarThe double substitution of \nXX before bar is again "unexpected".
tglplain2021-02-20 21:37:20
FWIW, I can't reproduce this misbehavior in current Postgres: I get a correct-looking result from
# select regexp_replace(E'foo\nbar', '^|\n', E'\nXX', 'g');
regexp_replace
----------------
+
XXfoo +
XXbar
(1 row)
I speculate that it got fixed as a side-effect of the constraint loop fixes we did awhile ago.
I thought you guys had absorbed those, though.
serhiy.storchakawiki2026-10-10 17:51:51
Same cause as [471101ffff]: with -all, each match was searched in the substring after the previous one, and ^ was allowed there whenever the previous character was a newline, even without -lineanchor. PostgreSQL, whose regex engine is derived from Tcl's, avoids this by passing the whole string with a search start offset.
Proposed fix in branch regexp-all-search-start, which does the same: regexp -all {^|\n} "foo\nbar" would return 2, and the regsub example would give a single XX before bar. With -lineanchor, ^ still matches after a newline. Tests regexp-29.4 to 29.7.
jan.nijtmanswiki2026-10-11 20:06:59
Dup of [471101ffff]
Log in (anonymous is fine) to add a comment.