Boost.Regex oddity

Does anyone know why the following code would output "no match"?

  boost::regex r(".*\\.");
  std::string s("app.test");
  if (boost::regex_match(s, r))
    std::cout << "match" << std::endl;
  else
    std::cout << "no match" << std::endl;

      

+2


source to share


1 answer


I believe regex_match () matches the entire string. Try regex_search () .

It would work with the following regex:



boost::regex r(".*\\..*");

      

and the regex_match () function . But then again, regex_search () is what you are probably looking for.

+4


source







All Articles