Overview
| Artifact ID: | 17e1a5f661aaca611a6fc9dbb63c1caefe1483ae2c070e8013f3fd8c0255fc1e |
|---|---|
| Ticket: | 471101ffffffffffffffffffffffffffffffffff
RE \A and ^ don't replace the same |
| User & Date: | serhiy.storchaka on 2026-10-10 17:51:51 |
Changes
- icomment:
Still the same in 8.6, 9.0 and 9.1. With <tt>-all</tt>, <tt>regexp</tt> and <tt>regsub</tt> restarted matching on the substring after the previous match, so <tt>\A</tt> matched again at each restart point; <tt>^</tt> was only protected by <tt>TCL_REG_NOTBOL</tt>. All other engines (PCRE, Perl, Python, Java, Ruby, and PostgreSQL, whose engine is derived from Tcl's) match <tt>\A</tt> only once. Word constraints are affected the same way, since they could not see the character before the restart point: <tt>regexp -all -inline {\m\w} "ab cd"</tt> returns <tt>a b c d</tt> instead of <tt>a c</tt>, and <tt>\y</tt> matches between any two word characters. Proposed fix in branch [/timeline?r=regexp-all-search-start|regexp-all-search-start]: successive matches are searched from the current offset in the whole string, so <tt>\A</tt> matches only at the start (or at the <tt>-start</tt> 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]. - login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"