C++ boost::regex multiples captures -


i'm trying recover multiples substrings boost::regex , put each 1 in var. here code :

unsigned int = 0; std::string string = "--perspective=45.0,1.33,0.1,1000"; std::string::const_iterator start = string.begin(); std::string::const_iterator end = string.end(); std::vector<std::string> matches; boost::smatch what; boost::regex const ex(r"(^-?\d*\.?\d+),(^-?\d*\.?\d+),(^-?\d*\.?\d+),(^-?\d*\.?\d+))");  string.resize(4);  while (boost::regex_search(start, end, what, ex) {     std::string stest(what[1].first, what[1].second);     matches[i] = stest;     start = what[0].second;     ++i; } 

i'm trying extract each float of string , put in vector variable matches. result, @ moment, can extract first 1 (in vector var, can see "45" without double quotes) second 1 in vector var empty (matches[1] "").

i can't figure out why , how correct this. question how correct ? regex not correct ? smatch incorrect ?

  1. firstly, ^ symbol beginning of line. secondly, \ must escaped. should fix each (^-?\d*\.?\d+) group (-?\\d*\\.\\d+). (probably, (-?\\d+(?:\\.\\d+)?) better.)

  2. your regular expression searches number,number,number,number pattern, not each number. add first substring matches , ignore others. fix this, can replace expression (-?\\d*\\.\\d+) or add matches stored in what matches vector:

 while (boost::regex_search(start, end, what, ex))  {       for(int j = 1; j < what.size(); ++j)        {             std::string stest(what[j].first, what[j].second);            matches.push_back(stest);       }       start = what[0].second;  } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -