fork download
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <complex>
  4. #include "assert.h"
  5. #include <cstdio>
  6. #include <regex.h>
  7. #include <stack>
  8. #include <time.h>
  9. #include <cstdlib>
  10. #include <ctype.h>
  11. #include <cctype>
  12. #include <queue>
  13. #include <cmath>
  14. #include <iostream>
  15. #include <sstream>
  16. #include <string>
  17. #include <cstring>
  18. #include <utility>
  19. #include <vector>
  20. #include <map>
  21. #include <numeric>
  22. #include <set>
  23. #include <unistd.h>
  24. #include <bitset>
  25. using namespace std;
  26.  
  27.  
  28. int main(){
  29.  
  30. regex_t reg;
  31.  
  32. string pattern = "[^tpr]{2,}";
  33. string str = "topcoder";
  34.  
  35. regmatch_t matches[1];
  36.  
  37. regcomp(&reg,pattern.c_str(),REG_EXTENDED|REG_ICASE);
  38.  
  39. if (regexec(&reg,str.c_str(),1,matches,0)==0) {
  40. cout << "Match " ;
  41. cout << str.substr(matches[0].rm_so,matches[0].rm_eo-matches[0].rm_so) ;
  42. cout << " found starting at: " ;
  43. cout << matches[0].rm_so ;
  44. cout << " and ending at " ;
  45. cout << matches[0].rm_eo ;
  46. cout << endl;
  47. } else {
  48. cout << "Match not found.";
  49. cout << endl;
  50. }
  51. regfree(&reg);
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 2864KB
stdin
Standard input is empty
stdout
Match code found starting at: 3 and ending at 7