regex_match
Determines if the regular expression e matches the entire target character sequence, which may be specified as std::string, a C-string, or an iterator pair.
You need to use regex_search
Determines if there is a match between the regular expression e and some subsequence in the target character sequence.
Also you can use regex_iterator
, example from here:
string text = "sp_call('%1','%2','%a');";
std::regex regexp("%[0-9]");
auto words_begin =
std::sregex_iterator(text.begin(), text.end(), regexp);
auto words_end = std::sregex_iterator();
std::cout << "Found "
<< std::distance(words_begin, words_end)
<< " words:\n";
for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
std::smatch match = *i;
std::string match_str = match.str();
std::cout << match_str << '\n';
}
Found 2 words:
%1
%2