fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <regex>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main ()
  10. {
  11. string string_array[] = {"http://w...content-available-to-author-only...s.com/reference/regex/regex_match/",
  12. "tcp://192.168.2.1:1234/hello/how/are/you",
  13. "https://mail.google.com/mail/u/0/?tab=wm#inbox/15178022db56df29?projector=1"};
  14. regex e("^(?:([A-Za-z]+):)?(\\/{0,3})([0-9.A-Za-z-]+)(?::(\\d+))?(?:\\/([^?#]*))?(?:\\?([^#]*))?(?:#(.*))?$");
  15.  
  16. for(int i=0; i<3; i++)
  17. {
  18. smatch sm;
  19. regex_match (string_array[i],sm,e);
  20.  
  21. for (unsigned i=1; i<sm.size(); ++i)
  22. {
  23. cout << "[" << sm[i] << "] ";
  24. }
  25.  
  26. cout << endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3548KB
stdin
Standard input is empty
stdout
[http] [//] [www.cplusplus.com] [] [reference/regex/regex_match/] [] [] 
[tcp] [//] [192.168.2.1] [1234] [hello/how/are/you] [] [] 
[https] [//] [mail.google.com] [] [mail/u/0/] [tab=wm] [inbox/15178022db56df29?projector=1]