Last active
May 22, 2019 07:23
-
-
Save iamazeem/7924068fe8564f8a22277fe48aa31496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Validate date using regex | |
// Format: YYYY/MM/DD | |
#include <iostream> | |
#include <regex> | |
bool isDateValid( const std::string& date ) | |
{ | |
std::regex regexDate { R"(\d{4}/\d{2}/\d{2})" }; | |
std::smatch match; | |
std::regex_match( date, match, regexDate ); | |
std::cout << match.str() << std::endl; | |
return !match.str().empty(); | |
} | |
int main() | |
{ | |
const std::string date { "2016/12/17" }; | |
std::cout << std::boolalpha << isDateValid( date ) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment