I'm using VS2010 and coding c++ console application and faced the problem
#include <regex>
using namespace std;
//...
if (!regex_match("abab",regex("(ab?)*")))
{
//the problem is - why we are here? why it doesn't match?
}
checked here http://regexpal.com/ - it matches
Very simple: regex_match only returns true if the entire sequence gets matched. You may want to use regex_search if you want to see if a string contains your regex.
"ab?" matches "aba", the repeater ("()*")make this match once. The remainder is "b", so it's not a full match.
I'm sorry, I misread the regex. It should be a full match. Weird enough:
regex_match("aab", regex("(ab?)*")) == true
Seems to be a bug within the stl used (tested with QT Creator 2010.05, makespec = VS2010). Replacing regex_match with regex_search in your code matches right, but the match_results are empty - indicating something still goes wrong.
With VS2012 all tests matched correctly.
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