https://www.cnblogs.com/linux-wang/p/8142825.html
const bool GetLogOutputDate(const string& strGetLine, string& strOutputDate) {
const char *ptext = strGetLine.c_str(); //来自Log文件
const char *pregexstr =
"([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})";
regex_t reg;
regmatch_t regmatch[100];
int ret = 0;
bool bRet = true;
do {
ret = regcomp(®, pregexstr, REG_EXTENDED | REG_NEWLINE);
if (ret != 0) {
bRet = false;
break;
} else {
ret = regexec(®, ptext, sizeof(regmatch) / sizeof(regmatch_t), regmatch, 0);
if (ret != REG_NOMATCH) {
int len = regmatch[0].rm_eo - regmatch[0].rm_so;
char buf[1024] = { 0 };
memcpy(buf, ptext + regmatch[0].rm_so, len);
strOutputDate = buf;
} else {
bRet = false;
break;
}
}
} while (false);
regfree(®);
return true;
}