Boost C++ Libraries: Ticket #4103: erase_all_regex does not work well with possibly empty strings. https://svn.boost.org/trac10/ticket/4103 <p> Here is a test case, I want to remove all the substrings that matches the regular expression '<code>\s*</code>': all spaces, tabs and similars. </p> <pre class="wiki"> $ cat test_case.cc #include &lt;boost/algorithm/string/regex.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; boost::regex const&amp; spaces() { static boost::regex rv("\\s*"); return rv; } int main() { std::string e1(" Leading spaces! Remove them all! "); std::string c1(e1); std::string e2("No trailing or leading... Remove them all!"); std::string c2(e2); boost::erase_all_regex(e1, spaces()); std::cout &lt;&lt; "Erased: -" &lt;&lt; e1 &lt;&lt; "-" &lt;&lt; std::endl; std::cout &lt;&lt; "Original: -" &lt;&lt; c1 &lt;&lt; "-" &lt;&lt; std::endl; std::cout &lt;&lt; std::endl; boost::erase_all_regex(e2, spaces()); std::cout &lt;&lt; "Erased: -" &lt;&lt; e2 &lt;&lt; "-" &lt;&lt; std::endl; std::cout &lt;&lt; "Original: -" &lt;&lt; c2 &lt;&lt; "-" &lt;&lt; std::endl; } $ g++ -lboost_regex -W -Wall -pedantic -o test_case test_case.cc $ ./test_case Erased: -Leading spaces! Remove them all! - Original: - Leading spaces! Remove them all! - Erased: -No trailing or leading... Remove them all!- Original: -No trailing or leading... Remove them all!- $ </pre><p> I think the expected output should not have spaces in the output string. Instead only the leading spaces are removed. </p> <p> While the problem still persist with '<code>\s*</code>' the bug apparead also with regex '<code>\s+</code>' in the version 1.41, but using the svn trunk downloaded yesterday it disappeared. It is worth to note because the bug is not very grave anymore. It is enough to use a regex that does not allow empty strings. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4103 Trac 1.4.3 Steven Watanabe Thu, 15 Apr 2010 14:56:16 GMT component changed; owner set https://svn.boost.org/trac10/ticket/4103#comment:1 https://svn.boost.org/trac10/ticket/4103#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Pavol Droba</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">string_algo</span> </li> </ul> Ticket Steven Watanabe Wed, 09 Jun 2010 22:55:25 GMT <link>https://svn.boost.org/trac10/ticket/4103#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4103#comment:2</guid> <description> <p> It looks like an empty match is taken as the sentinel to indicate that there is no match. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 28 Dec 2011 18:54:10 GMT</pubDate> <title>owner, component changed https://svn.boost.org/trac10/ticket/4103#comment:3 https://svn.boost.org/trac10/ticket/4103#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Pavol Droba</span> to <span class="trac-author">Marshall Clow</span> </li> <li><strong>component</strong> <span class="trac-field-old">string_algo</span> → <span class="trac-field-new">algorithm</span> </li> </ul> Ticket Marshall Clow Mon, 24 Sep 2012 17:42:29 GMT <link>https://svn.boost.org/trac10/ticket/4103#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4103#comment:4</guid> <description> <p> This is still around in 1.51; but since there's an easy workaround (use a non-empty regex), I'm inclined not to fix this. </p> <p> Comments? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 01 Oct 2012 15:33:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4103#comment:5 https://svn.boost.org/trac10/ticket/4103#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> Ticket