C ++ 11 regex :: icase不一致的行为 [英] C++11 regex::icase inconsistent behavior

查看:79
本文介绍了C ++ 11 regex :: icase不一致的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自类似perl的正则表达式,我希望以下代码在所有8种情况下都可以匹配正则表达式.但事实并非如此.我想念什么?

Coming from perl-like regular expressions, I expected the below code to match regex'es in all 8 cases. But it doesn't. What am I missing?

#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上运行:

Running with 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

推荐答案

对于将来的用户,已确认这是一个错误,并且根据

For future users, this was confirmed to be a bug, and it (and similar issues) are solved as of 8.1 according to this thread.

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

I suspect that the original author had a hand in bringing attention to this, but I figured maybe we could get this closed.

这篇关于C ++ 11 regex :: icase不一致的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆