Schupp

S5 regex

Jun 12th, 2018 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1.  
  2. #include <cstdlib>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <cstring>
  7. #include <iostream>
  8. #include <regex>
  9. #include <iterator>
  10. #include <string>
  11.  
  12.  
  13. using namespace std;
  14.  
  15. /*
  16.  * Matcht nicht wie es soll.
  17.  */
  18. int main(int argc, char** argv) {
  19. std::string test= "Netzwerk 20        00C1\n             +---+\n M 70.2   ---! & !\n E 64.2   ---!   !\n E 81.0   --O!   !\n E 81.1   --O!   !\n E 81.2   ---!   !\n E 81.3   --O!   !\n E 81.6   --O!   !\n E 81.4   --O!   !    +------+\n E 81.5   --O!   !--+-! S    ! M 72.3\n             +---+  ! +------+\n                    ! +------+\n                    +-! S    ! M 81.1\n                      +------+\n";
  20.  
  21.     string pattern[] ={ "([E][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])",
  22.                         "([A][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])",
  23.                         "([S][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])",
  24.                         "([M][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])"
  25.                        
  26.     };
  27.    
  28.     for (int n = 0; n < 2; n++) {
  29.    
  30.     regex rgx(pattern[n], std::regex::ECMAScript);
  31.     sregex_iterator next(test.begin(), test.end(), rgx);
  32.     sregex_iterator end;
  33.         while (next != end) {
  34.             smatch match = *next;
  35.             const std::string eam = match.str();
  36.  
  37.             regex exprRRepEAM(eam,regex::ECMAScript);
  38.             cout<<"gefunden:"<<eam<<endl;
  39.             test=std::regex_replace (test,exprRRepEAM,"XXX");
  40.             next++;
  41.        
  42.         }
  43.     }
  44.     cout<<test;
  45. }
Add Comment
Please, Sign In to add comment