14 Mar
2015
14 Mar
'15
4:31 p.m.
Hi, I am pretty much a complete novice to the boost::regex library, and stuck with the following snippet: std::string String = " (of 1000 elements; 67.10%)"; try { std::cout << boost::regex_match(String, boost::regex("^ (of \\d+ elements; .+%)$")) << std::endl; std::cout << boost::regex_match(String, boost::regex(" (of \\d+ elements;.+")) << std::endl; } catch(boost::regex_error const &) { std::cout << "caught boost::regex_error!"; } Two questions: First, why does the first not match? Second, why does the second throw? The idea of the regex is that the first number is an integer, and for the percentage number the formatting is unspecified but must terminate with '%'; otherwise all characters must match exactly. thanks, Thomas