I have no idea why the regular expression does not match the string 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 when I remove the last star, which multiplies a big string.
Please help me.
This may be a quirk of your library (or usage) in treating the regex greedily. (00) gets 00 (1*(01)*1*)* sucks up 1011 and then the remaining (10) doesn't match the one last 0. Then for some reason your library isn't deciding to backtrack and try another match (thanks @Paul Rubel, @marcog).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With