当
string str = “ab.txt”;
regex regexPattern("([a-z])+.txt");
smatch result;
//regex_match(str, result, re);
regex_match(str, result, regexPattern);
cout << result[1] << endl;
cout << result[2] << endl;
这样写的时候,你认为result[1]是a 2是b但实际只有b而且还是result[1]是b
而当你这样
string str = “ab.txt”;
regex regexPattern("([a-z])([a-z]).txt");
smatch result;
//regex_match(str, result, re);
regex_match(str, result, regexPattern);
cout << result[1] << endl;
cout << result[2] << endl;
结果又正常了
说明()配上+时候+只会给最后一个匹配上的字段套上



