Ok, thank you. I've understood something more about this boost's regex. But, I'm far from my real goal, yet. Say, I have some kind of strange string that contains a bithdate. For instance, say that I want to extract the date 21 June 1992 from !!eh?21**?junAn1992.
How can I solve this problem? Reading Boost's documentation it sounds very weard that one wants to extract data from a string and not just knowing if the regex matches.
#include <iostream>
#include <string>
#include <boost/regex.hpp>
int main()
{
// Let's start from printing out just the 21.
// So the regex I've thought is the following one:
boost::regex my_reg_expression ("[^\\d]*\\d{1,2}",
boost::regex_constants::icase);
// Here's the strange string:
std::string my_string = "!!eh21**?junAn1992pl6=";
boost::smatch m;
if (boost::regex_search(my_string, m, my_reg_expression,
boost::regex_constants::format_perl))
{
std::cerr << "m.size() returns " << m.size() << std::endl;
std::cerr << "m.str(0) == " << m.str(0) << std::endl;
}
else
{
std::cerr << "Sorry but regex has not matched. \n";
}
return 0;
}
it's really the same as any other regular expression. Yours matches everything up to the second digit, and that's what you get. You could use round parentheses to make the digits a sub expression, same as in the first example. Could you describe your "real goal" in more detail?