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
  • 103,386
  • 18
  • 232
  • 318
camino
  • 9,449
  • 19
  • 60
  • 105

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
  • 369,052
  • 73
  • 620
  • 1,021