I have looked at the previous questions to find the best way to look for a floating point value. My problem is I have a line that should contain at least 3 floating point values in addition to some other text. I want to extract the first three floating point values from the line and use them. However, I can only get boost::regex to give me the first value. What am I doing wrong? I do want to force at least one digit on each side of the decimal and force that a decimal must exist as well.
My example input string is
"this is a name" 39.789876 -83.997978 30.000000
My code looks like
std::string line = "\"this is a name\" 39.789876 -83.997978 30.000000";
static boost::regex llhNums_regex = boost::regex("[-]?[0-9]+[.][0-9]+");
boost::smatch resultsTwo;
if(boost::regex_search(line, resultsTwo, llhNums_regex))
{
std::cout << "Found results\n";
}
for(int i = 0 ; i<resultsTwo.size() ; ++i)
{
std::cerr << i << ": " << resultsTwo[i].str() << std::endl;
}
Yet resultsTwo.size()
is only 1 and it prints out just the first floating point value. How do I get all three values out? I am sure there is something basic with regular expressions I am misunderstanding, but I cannot figure it out.