fork download
  1. #include <iostream>
  2. #include <regex>
  3. using namespace std;
  4.  
  5. int main() {
  6. std::vector<std::string> strings;
  7. strings.push_back("T441_S45/1");
  8. strings.push_back("007_S4");
  9. strings.push_back("41_445T02_74");
  10.  
  11. std::regex reg(R"(^\D*(\d+)(?:\D+(\d+))?(?:\D+(\d+))?[\s\S]*)");
  12. for (size_t k = 0; k < strings.size(); k++)
  13. {
  14. std::cout << "Input string: " << strings[k] << std::endl;
  15. std::cout << "Replace result: "
  16. << std::regex_replace(strings[k], reg, "$1 $2 $3") << std::endl;
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout
Input string: T441_S45/1
Replace result: 441 45 1
Input string: 007_S4
Replace result: 007 4 
Input string: 41_445T02_74
Replace result: 41 445 02