Boost C++ Libraries: Ticket #7959: regex lookahead fails at about 95,000 chars https://svn.boost.org/trac10/ticket/7959 <p> The lookahead system fails if it must traverse about 95000 chars without a match. </p> <p> Test pattern: start((?!end).)*stuff </p> <p> Input: </p> <p> start nothing end start some stuff end start nothing end start more stuff end </p> <p> This will match the two start-end regions containing "stuff". However, insert about 95000 random characters into the first start-end region, and the search fails. </p> <p> Debugging on VC2008 shows a Microsoft C++ exception: boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;std::runtime_error&gt; &gt; </p> <p> I traced as far as finding that the error occurs on the first call to match_all_states(). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7959 Trac 1.4.3 John Maddock Fri, 01 Feb 2013 09:53:21 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7959#comment:1 https://svn.boost.org/trac10/ticket/7959#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> If you catch the exception you will see that it says: </p> <p> "Ran out of stack space trying to match the regular expression." </p> <p> Basically Regex sets an upper limit on how much memory it will grab when trying to find a match. If you up the values of BOOST_REGEX_MAX_BLOCKS and/or BOOST_REGEX_BLOCKSIZE in boost/regex/user.hpp and then rebuild everything (including the library), then the issue will disappear - or at least get shifted to larger texts before you hit the limit. Obviously if you set BOOST_REGEX_MAX_BLOCKS to something like INT_MAX then there is no limit - whether you think that's a good idea I'll leave up to you! </p> <p> But basically this is by design. </p> Ticket