fork(2) download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4.  
  5. int main()
  6. {
  7. std::string text("bbcaXXXXXY");
  8.  
  9. // std::regex ex("([abc]{2,4})(.{1})X*.");
  10. std::regex ex("(....)(.)X*.");
  11.  
  12. std::smatch results;
  13. if( std::regex_match(text, results, ex) )
  14. {
  15. auto index = 0;
  16. for( auto sub : results )
  17. {
  18. if( ++index == 1 ) // whole match
  19. continue;
  20.  
  21. std::cout << "----" << std::endl;
  22. if( sub.matched )
  23. {
  24. std::cout << sub.str() << std::endl;
  25. }
  26. else
  27. std::cout << "残念" << std::endl;
  28. }
  29. }
  30. }
  31.  
Success #stdin #stdout 0s 3068KB
stdin
Standard input is empty
stdout
----
bbca
----
aX