fork download
  1. #include <iostream>
  2. #include <regex>
  3. using namespace std;
  4.  
  5. int main() {
  6. string line = "echo 7/tcp\n";
  7. string regexStr = "^([A-Za-z][^ ]*)\\s+(\\d{1,5})/(tcp|udp)\\b[\\s\\S]*";
  8. regex rg(regexStr);
  9. smatch sm;
  10. if (regex_match(line, sm, rg)) {
  11. std::cout << sm[1] << std::endl;
  12. std::cout << sm[2] << std::endl;
  13. std::cout << sm[3] << std::endl;
  14. }
  15. return 0;
  16. }
Success #stdin #stdout 0s 3496KB
stdin
Standard input is empty
stdout
echo
7
tcp