0

I have searched and found similar questions, but no definitive answers for what I am looking for. For example, in the string: "I would like the number 98 to be found and printed, thanks." I would like "98" and "thanks" to be outputted, and only those strings. I have tried:

    regex pattern{R"(\d{2} | thanks)"}

But that only outputs 98. I have also tried

    regex pattern{R"((\d{2})(thanks))"} 

But this does not work either. Help would be appreciated! Thanks.

Note: I realize I can do this easily using two patterns, but I am seeing if you can do this using specifically one pattern.

Note 2: This is the rest of the program:

#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main() {

  regex pattern{R"(\d{2}|thanks)"};

  string to_search = "I would like the number 98 to be found and printed, thanks.";
  smatch matches;

  regex_search(to_search, matches, pattern);

  for (auto match : matches) {
    cout << match << endl;
  }

  return 0;

}
cm1745
  • 120
  • 2
  • 12

0 Answers0