Boost C++ Libraries: Ticket #1636: Bug in regex? https://svn.boost.org/trac10/ticket/1636 <p> void <a class="missing wiki">RegexTest</a>() { </p> <blockquote> <p> char *pszMessage = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"; static const boost::regex e("<sup>(.*?,)<a class="missing report" title="report does not exist">{11}</a>P"); boost::cmatch result; if (boost::regex_search(pszMessage, result, e)) { </sup></p> <blockquote> <p> cout &lt;&lt; result.str() &lt;&lt; "$" &lt;&lt; result.length() &lt;&lt; endl; </p> </blockquote> <p> } else </p> <blockquote> <p> cout &lt;&lt; "result empty" &lt;&lt; endl; </p> </blockquote> </blockquote> <p> } </p> <p> <strong>An exception raised by the boost regex-engine when testing with the code above in visual c++ 6.0</strong> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1636 Trac 1.4.3 John Maddock Sun, 30 Mar 2008 16:01:04 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1636#comment:1 https://svn.boost.org/trac10/ticket/1636#comment:1 <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> <p> This is expected behaviour: Perl-style regular expression matching is an NP-complete problem in general, and any expression that looks like: (something*)* may experience these issues eventually. Boost.Regex tries to prevent "runaway" expressions by throwing an exception if the complexity of the match looks like it's going to exceed a certain maximum - and this is what's happening here. </p> <p> Using a more precise expression would fix this - for example </p> <p> "([<sup>,]*?,)<a class="missing report" title="report does not exist">{11}</a>P" </sup></p> <p> or </p> <p> "(?&gt;.*?,)<a class="missing report" title="report does not exist">{11}</a>P" </p> <p> would fix this - and improve performance a lot into the bargain. </p> <p> HTH, John Maddock. </p> Ticket