Long regex expression causes error

前端 未结 1 1713
一向
一向 2021-01-23 09:03

This

std::regex line(\"[\\s]+\\+?[0-9]+.[0-9]+[\\s]+\\+?[0-9]+.[0-9]+[\\s]+\\+?[0-9]+.[0-9]+[\\s]\");

line causes this

Exceptio         


        
相关标签:
1条回答
  • 2021-01-23 09:22

    You either need to escape the back slashes with \\ (two for one), or use a raw string literal like this:

    regex line{R"([\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s]+\+?[0-9]+.[0-9]+[\s])"};
    

    Raw string literals surround the string with (at least) R"( and )".

    Read more about raw string literals HERE - Syntax (6).

    0 讨论(0)
提交回复
热议问题