作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
来自类似 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
最佳答案
对于 future 的用户,这被确认为一个错误,并且它(和类似的问题)根据 this 在 8.1 中得到解决。线程。
我怀疑原作者参与了引起对此的关注,但我想也许我们可以关闭它。
关于C++11 regex::icase 不一致行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37757863/
这个问题在这里已经有了答案: C++11 regex::icase inconsistent behavior (1 个回答) 去年关闭。 此函数应该返回字符串中元音的第一个实例,但它仅适用于小写字母
// regex_replace example #include #include #include #include int main () { std::string INPUT =
来自类似 perl 的正则表达式,我希望下面的代码在所有 8 种情况下都能匹配正则表达式。但事实并非如此。我错过了什么? #include #include #include using nam
我在 VS2013 Update 4 和 VS2015 Update 3 中使用以下 C++ 代码,使用字符范围尝试不区分大小写地匹配并替换出现的位置: std::wstring strSource(
我是一名优秀的程序员,十分优秀!