【发布时间】:2017-01-26 00:38:33
【问题描述】:
我对提升正则表达式库很陌生。以下示例代码用于检查输入的日期是否遵循YYYY-MM-DD 格式。但是,正则表达式似乎有错误。它总是返回'sfalse。
*
- 我正在 Windows 上运行控制台应用程序。
* 正则表达式取自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;
}
【问题讨论】: