關于正則表達式的gcc 4.8或更早的bug嗎?我試圖在C ++ 11代碼中使用std :: regex,但看起來支持有點兒錯誤。一個例子:#include <regex>#include <iostream>int main (int argc, const char * argv[]) {
std::regex r("st|mt|tr");
std::cerr << "st|mt|tr" << " matches st? " << std::regex_match("st", r) << std::endl;
std::cerr << "st|mt|tr" << " matches mt? " << std::regex_match("mt", r) << std::endl;
std::cerr << "st|mt|tr" << " matches tr? " << std::regex_match("tr", r) << std::endl;}輸出:st|mt|tr matches st? 1st|mt|tr matches mt? 1st|mt|tr matches tr? 0當使用gcc(MacPorts gcc47 4.7.1_2)4.7.1編譯時,使用g++ *.cc -o test -std=c++11g++ *.cc -o test -std=c++0x要么g++ *.cc -o test -std=gnu++0x此外,如果我只有兩種替代模式st|mt,那么正則表達式效果很好,例如,看起來最后一種模式由于某些原因而不匹配。該代碼適用于Apple LLVM編譯器。有關如何解決問題的任何想法?更新一個可能的解決方案是使用組來實現(xiàn)多個替代方案,例如(st|mt)|tr。
- 3 回答
- 0 關注
- 2646 瀏覽
添加回答
舉報
0/150
提交
取消