I am quite new to boost regex library.The following sample code is used to check if the entered date is following the YYYY-MM-DD
format.However,there seems to be an error in the regex. It always return'sfalse
.
*
- I am running the console application on windows.
* the regex was taken from here
bool regexValidate(string teststring)
{
boost::regex ex("^(20\\d{2})(\\d{2})(\\d{2})");
if (boost::regex_match(teststring, ex)) {
cout << "true";
return true;
}
else {
return false;
}
}
int main()
{
string teststr = "2016-05-15";
cout << teststr << " is ";
if (regexValidate( teststr)) {
cout << " valid!" << endl;
}
else {
cout << " invalid!" << endl;
}
system("PAUSE");
return 0;
}