It seems that find_format_all() calls the formatter with an invalid match when the end of the input is reached. Is this a bug? Am I missing something? Example: // A Boost.StringAlgo Formatter expecting to be called for regex matches for (\d+\.)(\d+) struct NextVersionNumber { template<class RegexMatchT> std::string operator()(const RegexMatchT& M)const { // Without this check, we end up with a bad_lexical_cast exception, // because operator() ends up being called twice: // First with a good match, and then with an emtpy one if (!Match){ return ""; } using boost::lexical_cast; return M.match_results()[1] + lexical_caststd::string(lexical_cast<unsigned int>(M.match_results()[2]) + 1); } }; int main() { namespace bsa = boost::algorithm; const std::string s("version is 1.0"); // Outputs: // Next version is: 1.1 std::cout << "Next version is: " << bsa::find_format_all_copy( s, bsa::regex_finder(boost::regex("(\\d+\\.)(\\d+)")), NextVersionNumber() ); return 0; }