实际上,我尝试在多行字符串中查找正则表达式,但我认为在新行之后查找下一个正则表达式(等于'\n')的方法错误。这是我的正则表达式:
#include <iostream>
#include <fstream>
#include <sstream>
#include <regex>
#define USE ".*[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}.*(?:\\n)*"
int main(int argc, char **argv)
{
std::stringstream stream;
std::filebuf *buffer;
std::fstream fs;
std::string str;
std::regex regex(USE);
if (argc != 2)
{
std::cerr << "Think to the use !" << std::endl;
return (-1);
}
fs.open(argv[1]);
if (fs)
{
stream << (buffer = fs.rdbuf());
str = stream.str();
if (std::regex_match(str, regex))
std::cout << "Yes" << std::endl;
else
std::cout << "No" << std::endl;
fs.close();
}
return (0);
}