C ++ 11 regex :: icase不一致行为

时间:2016-06-10 22:16:31

标签: c++ regex c++11 gcc gcc5.2

来自类似perl的正则表达式,我期望下面的代码在所有8种情况下匹配正则表达式。但事实并非如此。我错过了什么?

#include <iostream>
#include <regex>
#include <string>

using namespace std;

void check(const string& s, regex re) {
    cout << s << " : " << (regex_match(s, re) ? "Match" : "Nope") << endl;
}

int main() {
    regex re1 = regex("[A-F]+", regex::icase);
    check("aaa", re1);
    check("AAA", re1);
    check("fff", re1);
    check("FFF", re1);
    regex re2 = regex("[a-f]+", regex::icase);
    check("aaa", re2);
    check("AAA", re2);
    check("fff", re2);
    check("FFF", re2);
}

使用gcc 5.2运行:

$ g++ -std=c++11 test.cc -o test && ./test
aaa : Match
AAA : Match
fff : Nope
FFF : Match
aaa : Match
AAA : Match
fff : Match
FFF : Nope

1 个答案:

答案 0 :(得分:2)

对于将来的用户,这被确认是一个错误,并且根据this线程从8.1版开始解决了该错误(以及类似问题)。

我怀疑原始作者对此有所帮助,但我认为也许可以解决这个问题。