我已经查看了前面的问题以找到查找浮点值的最佳方法。我的问题是我有一行应该包含至少3除了一些其他文字的浮点值。我想从行中提取前三个浮点值并使用它们。但是,我只能得到boost :: regex给我第一个值。我究竟做错了什么?我希望强制小数的每一边至少有一位数字,并强制小数位数也必须存在。正则表达式多重浮点型
我的例子输入字符串是
"this is a name" 39.789876 -83.997978 30.000000
我的代码看起来像
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;
}
然而resultsTwo.size()
只有1和它打印出来只是第一个浮点值。我如何获得所有三个值?我确信有一些基本的东西是我误解的正则表达式,但我无法弄清楚。
对于直接答案的正则表达式的问题:HTTPS:/ /stackoverflow.com/questions/3122344/boost-c-regex-how-to-get-multiple-matches?noredirect=1& lq = 1 – sehe