fork(1) download
  1. #include <iostream>
  2. #include <regex>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. string str = "Richard ///[][][12345/678910111213141516] was murdered by Ralph Jordan[/[54321/161514131211109876]";
  8. regex rgx1(R"(([A-Z]\w*\s*\S*)\[(\d+)?(?:\/(\d+))?\])");
  9. smatch smtch;
  10. while (regex_search(str, smtch, rgx1)) {
  11. std::cout << "Name: " << smtch[1] << std::endl;
  12. std::cout << "ID1: " << smtch[2] << std::endl;
  13. std::cout << "ID2: " << smtch[3] << std::endl;
  14. str = smtch.suffix().str();
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 0s 3544KB
stdin
Standard input is empty
stdout
Name: Richard ///[][]
ID1: 12345
ID2: 678910111213141516
Name: Ralph Jordan[/
ID1: 54321
ID2: 161514131211109876