Schupp icon

S5 regex

Schupp | PRO | 01/28/21 09:42:10 PM UTC (Edited) | 0 ⭐ | 438 👁️ | Never ⏰ | []
C++ |

1.49 KB

|

None

|

0 👍

/

0 👎

 
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <regex>
#include <iterator>
#include <string>
 
 
using namespace std;
 
/*
 * Matcht nicht wie es soll.
 */
int main(int argc, char** argv) {
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";
 
    string pattern[] ={ "([E][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])",
                        "([A][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])",
                        "([S][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])",
                        "([M][ ]{1,3}{0,4}[0-9]{1,3}[.][0-7])"
                        
    };
    
    for (int n = 0; n < 2; n++) {
    
    regex rgx(pattern[n], std::regex::ECMAScript);
    sregex_iterator next(test.begin(), test.end(), rgx);
    sregex_iterator end;
        while (next != end) {
            smatch match = *next;
            const std::string eam = match.str();
 
            regex exprRRepEAM(eam,regex::ECMAScript);
            cout<<"gefunden:"<<eam<<endl;
            test=std::regex_replace (test,exprRRepEAM,"XXX");
            next++;
       
        }
    }
    cout<<test;
}

Comments