Eingabe mit RegExp prüfen

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Eingabe mit RegExp prüfen

    Heho, Coder-Community.
    Ich kann guts Regex noch aus php und javascript
    und würde gerne wissen, wie ich einen string
    in c++ mit regexp prüfe.

    Kann mir schnell jemand den Header geben und
    wie ich die Funktion benutze?

    Edit

    Ich habe mir jetzt die Greta-Lib von microsoft geholt und
    zu meinen anderen libs kopiert.
    Trotzdem gibt der Beispielcode im Greatazip

    Quellcode

    1. #include <iostream>
    2. #include <string>
    3. #include “regexpr2.h”
    4. using namespace std;
    5. using namespace regex;
    6. int main() {
    7. match_results results;
    8. string str( “The book cost $12.34” );
    9. rpattern pat( “\\$(\\d+)(\\.(\\d\\d))?” );
    10. // Match a dollar sign followed by one or more digits,
    11. // optionally followed by a period and two more digits.
    12. // The double-escapes are necessary to satisfy the compiler.
    13. match_results::backref_type br = pat.match( str, results );
    14. if( br.matched ) {
    15. cout << “match success!” << endl;
    16. cout << “price: ” << br << endl;
    17. } else {
    18. cout << “match failed!” << endl;
    19. }
    20. return 0;
    21. }
    Alles anzeigen


    nur Fehlermeldungen.