On 14/03/2015 16:31, Thomas wrote:
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? The "(" characters are grouping operators, use "\\(" for a literal (.
Second, why does the second throw?
Well if you'd printed out the message contained in the exception it would have told ;) Same reason as above: you have a grouping ( start but no matching ). John.
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
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users