长正则表达式导致错误

Long regex expression causes error

这个

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

行导致这个

Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at memory location 0x000000F751EFEAB0.
Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at memory location 0x000000F751EFEAB0.
Unhandled exception at 0x00007FFE39E69E08 in DosyaOkuHizli.exe: Microsoft C++ exception: std::regex_error at memory location 0x000000F751EFEAB0.

但是这个

std::regex line("abc");

没有。

长表达式在这里起作用:https://www.myregextester.com/index.php

我只是想在其他数据之间获取 3 个后续浮点值。


Visual studio 2015 社区版调试 64 位。 Windows10.

您需要使用 \(二合一)转义反斜杠,或者使用像这样的原始字符串文字:

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

原始字符串文字用(至少)R"()".

包围字符串

阅读有关原始字符串文字的更多信息HERE - 语法 (6)。