#include <iostream>
#include <string>
#include <regex>
int main()
{
std::string text("bbcaXXXXXY");
std::regex ex("([abc]{2,4})(.{1})X*.");
//std::regex ex("(....)(.)X*.");
std::smatch results;
if( std::regex_match(text, results, ex) )
{
auto index = 0;
for( auto sub : results )
{
if( ++index == 1 ) // whole match
continue;
std::cout << "----" << std::endl;
if( sub.matched )
{
std::cout << sub.str() << std::endl;
}
else
std::cout << "残念" << std::endl;
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8cmVnZXg+CiAKaW50IG1haW4oKQp7CiAgICBzdGQ6OnN0cmluZyB0ZXh0KCJiYmNhWFhYWFhZIik7CiAKICAgICAgc3RkOjpyZWdleCBleCgiKFthYmNdezIsNH0pKC57MX0pWCouIik7Ci8vc3RkOjpyZWdleCBleCgiKC4uLi4pKC4pWCouIik7CiAKICAgICAgICBzdGQ6OnNtYXRjaCByZXN1bHRzOwogICAgICAgIGlmKCBzdGQ6OnJlZ2V4X21hdGNoKHRleHQsIHJlc3VsdHMsIGV4KSApCiAgICAgICAgewogICAgICAgICAgICAgICAgYXV0byBpbmRleCA9IDA7CiAgICAgICAgICAgICAgICBmb3IoIGF1dG8gc3ViIDogcmVzdWx0cyApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKCArK2luZGV4ID09IDEgKSAvLyB3aG9sZSBtYXRjaAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogCiAgICAgICAgICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCAiLS0tLSIgPDwgc3RkOjplbmRsOwogICAgICAgICAgICAgICAgICAgICAgICBpZiggc3ViLm1hdGNoZWQgKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RkOjpjb3V0IDw8IHN1Yi5zdHIoKSA8PCBzdGQ6OmVuZGw7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCAi5q6L5b+1IiA8PCBzdGQ6OmVuZGw7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQp9Cg==