4

I encounter a weird problem when using regex in c++11 (ubuntu 14.4 ,gcc 4.8.2)

#include <iostream>
#include <regex>
using namespace std;
int main()
{
    regex r("(abc|aa.*|bb.*)");
    cout<<regex_match("bb11",r)<<endl;  //return false
    cout<<regex_match("aa11",r)<<endl;  //return true
    cout<<regex_match("abc",r)<<endl;   //return true
    return 0;
}

while

int main()
{
    regex r("(aa.*|bb.*|cc.*)");
    cout<<regex_match("bb11",r)<<endl;  //return true
    cout<<regex_match("aa11",r)<<endl;  //return true
    cout<<regex_match("abc",r)<<endl;   //return false
    return 0;
}

I am wondering why "bb11" got different result?

Praetorian
  • 106,671
  • 19
  • 240
  • 328
camino
  • 10,085
  • 20
  • 64
  • 115

1 Answers1

4

std::regex is not supported in GCC until 4.9.

In 4.8.2 you'll get all sorts of odd behaviour.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055