Boost logo

Boost Users :

Subject: [Boost-users] [regex] stuck with expression syntax / exception
From: Thomas (firespot71_at_[hidden])
Date: 2015-03-14 12:31:45


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net