2017-06-22 63 views
0

龍正則表達式將導致錯誤

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位。 10.視窗

+0

什麼是輸入字符串? – revo

+0

foo bar somewhitespace +123.324 somewhitespace 33434.4545 somewhitespace -3434.4545 somewhitespace biz baz baz –

回答

3

您也需要逃離回來\\(買一送一)斜槓或使用原始字符串字面量是這樣的:

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

原始字符串文字環繞以字符串(至少)和。

瞭解有關原始字符串文字的更多信息HERE - 語法(6)。