When I run this code:
当我运行此代码时:
#include <iostream>
#include <regex>
using namespace std;
main () {
const string source = "hello(abc_def)";
const regex regexp("he(l)lo.*");
smatch m;
if (regex_match(source, m, regexp)) {
cout << "Found, group 1 = " << m[1].str() << endl;
} else {
cout << "Not found" << endl;
}
const regex regexp2("hello\((\w+)\)");
try {
if (regex_match(source, m, regexp2)) {
cout << "Found, group 1 = " << m[1].str() << endl;
} else {
cout << "Not found" << endl;
}
} catch(const exception& exc) {
cout << "Got exception: " << exc.what() << endl;
}
}
#include <i