Boost C++ Libraries: Ticket #589: regex_replace bug https://svn.boost.org/trac10/ticket/589 <pre class="wiki">boost::tregex e("(.*)"); strResult = boost::regex_replace("a", e, "$1b"); strResult now equals "abb", but should be "ab". My e-mail: kdn01003@student.mdh.se </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/589 Trac 1.4.3 John Maddock Wed, 22 Mar 2006 10:28:06 GMT <link>https://svn.boost.org/trac10/ticket/589#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/589#comment:1</guid> <description> <pre class="wiki">Logged In: YES user_id=14804 This is by design, and is compatible with the way Perl does things: two matches are found, the first matches the "a", the second matches the zero length string immediately after the "a". Therefore two replacements are performed, and hense the output. Use .+ instead of .* if you don't want to find zero length matches. John Maddock </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Wed, 22 Mar 2006 10:28:07 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/589#comment:2 https://svn.boost.org/trac10/ticket/589#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> Ticket coffman@… Tue, 13 Dec 2011 20:52:30 GMT severity set https://svn.boost.org/trac10/ticket/589#comment:3 https://svn.boost.org/trac10/ticket/589#comment:3 <ul> <li><strong>severity</strong> → <span class="trac-field-new">Problem</span> </li> </ul> <p> I have found this behavior still exists even when using posix basic or extended regexes. While this behavior may be correct for perl regexes it doesn't seem to be correct for posix basic or extended regexes. </p> <p> std::string s("a"); const boost::regex e("(.*)", boost::regex::extended); std::string result = boost::regex_replace(s, e, "$&amp;b"); </p> <p> The result is "abb" </p> <p> If I use gnu's sed utility (GNU sed version 4.1.2) instead I get "ab" </p> <p> echo a | sed -r "s/(.*)/\1b/g" </p> <p> and gnu's sed utility claims to use posix extended regex expressions when called with the -r option. </p> Ticket coffman@… Wed, 14 Dec 2011 15:42:19 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/589#comment:4 https://svn.boost.org/trac10/ticket/589#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">Invalid</span> </li> </ul> Ticket John Maddock Sat, 07 Jul 2012 18:08:03 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/589#comment:5 https://svn.boost.org/trac10/ticket/589#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/79339" title="Fix regex_iterator and regex_replace to do what grep/sed do for ...">[79339]</a>) Fix regex_iterator and regex_replace to do what grep/sed do for multiple repeats when matching in POSIX mode. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/589" title="#589: Bugs: regex_replace bug (closed: fixed)">#589</a>. </p> Ticket John Maddock Sat, 07 Jul 2012 18:09:08 GMT description changed https://svn.boost.org/trac10/ticket/589#comment:6 https://svn.boost.org/trac10/ticket/589#comment:6 <ul> <li><strong>description</strong> modified (<a href="/trac10/ticket/589?action=diff&amp;version=6">diff</a>) </li> </ul> <p> This is now fixed in Trunk provided match_posix is passed to regex_replace or regex_iterator. </p> Ticket John Maddock Mon, 16 Jul 2012 08:38:29 GMT <link>https://svn.boost.org/trac10/ticket/589#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/589#comment:7</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/79556" title="Merge collected bug fixes from Trunk: Refs #589. Refs #7032. Refs ...">[79556]</a>) Merge collected bug fixes from Trunk: Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/589" title="#589: Bugs: regex_replace bug (closed: fixed)">#589</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7032" title="#7032: Bugs: Prevent tool Bug Fix. (closed: fixed)">#7032</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7084" title="#7084: Bugs: memory leak in fileiter.cpp (closed: fixed)">#7084</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6346" title="#6346: Bugs: boost::regex::begin() and boost::regex::end() always return 0 (closed: fixed)">#6346</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>