简体   繁体   中英

C++ regex matches on ideone.com but not in Android NDK build

I have the following program working correctly in 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.

However, the same code run in native code on Android (built using ndk-build with gnustl_shared) fails (does not match).

If regexes aren't properly supported under Android, shouldn't my build fail to compile? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM