Regular expression in C ++ / Star problem

I don't know why the regex doesn't match the line below:

int main(){

    string seq = "0010110";
    regex rgx("((1*(01)*1*)*)(00)(1*(01)*1*)*(10)");

    cout<<regex_match(seq, rgx)<<endl;
    system("pause");
    return 0;
}

The problem is resolved by removing the last star that multiplies a large string.

Please help me.

+3
source share
1 answer

This may be a quirk of your library (or use) with regex greed. (00)gets 00 (1*(01)*1*)*sucks up 1011, and then the remaining one (10)does not match the last. Then, for some reason, your library does not decide to step back and try another match (thanks @Paul Rubel, @marcog).

+3
source

All Articles