3

I have this simple C++ code with RegExp crashes on Android but works fine on OS X:

std::string str = "1x0-4x0";
std::regex regexRule( "([0-9]+)x([0-9]+)-([0-9]+)x([0-9]+)" );
std::smatch piecesMatch;
if ( std::regex_match( str, piecesMatch, regexRule ) )
    std::cout << "regex_match!\n";

Why does it crash? Am I missed something?

It compiles without any warnings.

GCC 4.8

JavaRunner
  • 2,455
  • 5
  • 38
  • 52

2 Answers2

3

Early version of gcc does not have full support on C++11. You could the check the version in your NDK.

gcc-4.8.5 on CentOS 7

terminate called after throwing an instance of 'std::regex_error'
  what():  regex_error
Aborted (core dumped)

gcc-5.2.1

regex_match!
kangshiyin
  • 9,681
  • 1
  • 17
  • 29
2

You are probably using NDK version with gcc 4.8. regex was officially announced to be supported since gcc 4.9. NDK uses gcc 4.9 in the recent versions i.e. 11b.

also see here : Is gcc 4.8 or earlier buggy about regular expressions?

Community
  • 1
  • 1
marcinj
  • 48,511
  • 9
  • 79
  • 100
  • Updated my NDK to up-to-date version and now I use gcc-4.9 instead of 4.8. Now it works fine. Thanks. – JavaRunner Apr 25 '16 at 12:56
  • Actually in NDK 11 gcc 4.8 was removed and gcc 4.9 is used for all targets. But 4.9 as I see was available for some time - as I see since NDK v. 10. – marcinj Apr 25 '16 at 13:20