C ++ 11的regex :: ICASE不一致的行为

问题描述 投票:6回答:1

从类似Perl的正则表达式的到来,我期待下面的代码以匹配8例regex'es。但事实并非如此。我在想什么?

#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
c++ regex c++11 gcc gcc5.2
1个回答
2
投票

对于未来的用户来说,这被证实是一个错误,它(以及类似的问题)根据this线程解决为8.1。

我怀疑原作者有一只手在将注意力集中到这一点,但我想也许我们可以得到这个关闭。

© www.soinside.com 2019 - 2024. All rights reserved.