[英]C++ regex matches on ideone.com but not in Android NDK build
I have the following program working correctly in ideone我有以下程序在ideone 中正常工作
#include <iostream>
#include <regex>
using namespace std;
int main() {
if (regex_match("test", regex("^[_a-z0-9]{3,12}$"))) {
cout << "match" << endl;
} else {
cout << "no match" << endl;
}
return 0;
}
It matches as expected.它按预期匹配。 Just checking for a string containing between 3 and 12 alphanumeric characters or underscores.只需检查包含 3 到 12 个字母数字字符或下划线的字符串。
However, the same code run in native code on Android (built using ndk-build with gnustl_shared) fails (does not match).但是,在 Android 上的本机代码中运行的相同代码(使用 ndk-build 和 gnustl_shared 构建)失败(不匹配)。
If regexes aren't properly supported under Android, shouldn't my build fail to compile?如果 Android 下不正确支持正则表达式,我的构建不应该无法编译吗? Am I missing something obvious here?我在这里遗漏了一些明显的东西吗?
I have the same issue today, and in my own experience, just change the "_" position in the expression.我今天遇到了同样的问题,根据我自己的经验,只需更改表达式中的“_”位置即可。
for my example, just replace对于我的例子,只需替换
std::regex reg("[^. _A-Za-z0-9]");
with和
std::regex reg("[^. A-Za-z0-9_]");
and it works fine, maybe it is because the gcc version is too old.它工作正常,也许是因为gcc版本太旧了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.