mardi 14 janvier 2020

Using complex regexp cause error - stray \ in program

I created a regexp to parse hMailServer logs:

^\"SMTPD\"\t(\d+)\t(\d+)\t"([0-9-0-9:\s.]+)"\t"([0-9.]+)"\t"(\w+):\s(.+)+"$

I tested it on regexr.com and it's working.

Now, when I try to write it in C++ using raw string literal, it doesn't work.

Code:

std::string RegExpStr = R"(^\"SMTPD\"\t(\d+)\t(\d+)\t"([0-9-0-9:\s.]+)"\t"([0-9.]+)"\t"(\w+):\s(.+)+"$)";

Error:

main.cpp:88:76: error: stray '\' in program
   88 |     std::string RegExpStr = R"(^\"SMTPD\"\t(\d+)\t(\d+)\t"([0-9-0-9:\s.]+)"\t"([0-9.]+)"\t"(\w+):\s(.+)+"$)";
      |                                                                            ^

It complained on \t.

How to fix this?

Aucun commentaire:

Enregistrer un commentaire