Regex ("(abc | aa. * | Bb. *)") Vs regex ("(aa. * | Bb. * | Cc. *)");

I'm having 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;
}

and

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 wonder why "bb11" got a different result?

+4
source share
1 answer

std::regexnot supported in GCC until 4.9 .

In 4.8.2 you get all kinds of odd behavior.

+4
source

Source: https://habr.com/ru/post/1542576/


All Articles