/*
Regex para validar determinado formato de data
https://pt.stackoverflow.com/q/272539/53463
*/
#include <iostream>
#include <regex>
int main() {
constexpr char text[]{"29/feb/2020"};
std::regex re(R"((?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|j(?:an|u[nl])|ma[ry]|a(?:pr|ug)|sep|oct|nov|dec|feb)|(29|30)([-/.])(0?[13-9]|1[0-2]|j(?:an|u[nl])|ma[ry]|a(?:pr|ug)|sep|oct|nov|dec)|(31)([-/.])(0?[13578]|1[02]|jan|ma[ry]|jul|aug|oct|dec))(?:\2|\5|\8)(0{2,3}[1-9]|0{1,2}[1-9]\d|0?[1-9]\d{2}|[1-9]\d{3})|(29)([-/.])(0?2|feb)\12(\d{1,2}(?:0[48]|[2468][048]|[13579][26])|(?:0?[48]|[13579][26]|[2468][048])00)))");
std::cmatch match;
bool valid = std::regex_match(text, match, re);
if (valid) {
std::cout << "Data válida: " << match[0] << std::endl
<< "Dia: " << match[1] << match[4] << match[7] << match[11] << std::endl
<< "Mês: " << match[3] << match[6] << match[9] << match[13] << std::endl
<< "Ano: " << match[10] << match[14] << std::endl;
} else {
std::cout << "Data inválida!!";
}
return 0;
}
LyoKICAgIFJlZ2V4IHBhcmEgdmFsaWRhciBkZXRlcm1pbmFkbyBmb3JtYXRvIGRlIGRhdGEKICAgIGh0dHBzOi8vcHQuc3RhY2tvdmVyZmxvdy5jb20vcS8yNzI1MzkvNTM0NjMKKi8KCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHJlZ2V4PgoKaW50IG1haW4oKSB7CiAgICBjb25zdGV4cHIgY2hhciB0ZXh0W117IjI5L2ZlYi8yMDIwIn07CiAgICBzdGQ6OnJlZ2V4IHJlKFIiKCg/Oig/OigwP1sxLTldfDFcZHwyWzAtOF0pKFstLy5dKSgwP1sxLTldfDFbMC0yXXxqKD86YW58dVtubF0pfG1hW3J5XXxhKD86cHJ8dWcpfHNlcHxvY3R8bm92fGRlY3xmZWIp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