I was experimenting with regular expression in trying to make an answer to this question, and found that while regex_match
finds a match, regex_search
does not.
The following program was compiled with g++ 4.7.1:
#include <regex>
#include <iostream>
int main()
{
const std::string s = "/home/toto/FILE_mysymbol_EVENT.DAT";
std::regex rgx(".*FILE_(.+)_EVENT\.DAT.*");
std::smatch match;
if (std::regex_match(s.begin(), s.end(), rgx))
std::cout << "regex_match: match
";
else
std::cout << "regex_match: no match
";
if (std::regex_search(s.begin(), s.end(), match, rgx))
std::cout << "regex_search: match
";
else
std::cout << "regex_search: no match
";
}
Output:
regex_match: match regex_search: no match
Is my assumption that both should match wrong, or might there a problem with the library in GCC 4.7.1?
See Question&Answers more detail:os