相关疑难解决方法(0)

关于正则表达式的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;
}
Run Code Online (Sandbox Code Playgroud)

输出:

st|mt|tr matches st? 1
st|mt|tr matches mt? 1
st|mt|tr matches tr? 0
Run Code Online (Sandbox Code Playgroud)

当使用gcc(MacPorts gcc47 4.7.1_2)4.7.1编译时,使用

g++ *.cc -o test -std=c++11 …
Run Code Online (Sandbox Code Playgroud)

c++ regex gcc libstdc++ c++11

98
推荐指数
2
解决办法
3万
查看次数

C++ 11正则表达式匹配

我在C++ 11中尝试一个相当简单的正则表达式匹配(使用gcc 4.7.2),但是我遇到了很多麻烦.尝试使用构造模式

std::regex unquoted(R"regex(\s*([^",]+)\s*)regex");
Run Code Online (Sandbox Code Playgroud)

导致构造函数std::regex_error使用代码抛出异常std::regex_constants::error_escape.在线的几个正则表达式测试人员对同一个表达式没有任何问题,我尝试使用不同的一些不同的语法选项无济于事.C++正则表达式语法是否存在根本不同的东西,我没有理解?

c++ regex gcc

11
推荐指数
1
解决办法
5885
查看次数

标签 统计

c++ ×2

gcc ×2

regex ×2

c++11 ×1

libstdc++ ×1