我要承認使用正則表達式在文本文件中的一些行,但regex_match不匹配任何行,即使我用正則表達式靠山(「*」)Regex_match不匹配文件
string dirin = "/home/user/in.srt";
string dirout = "/home/user/out.srt";
ifstream in(dirin.c_str());
ofstream out(dirout.c_str());
string line;
// regex patron("(\\d{2}):(\\d{2}):(\\d{2}),(\\d{3})\\s-->\\s(\\d{2}):(\\d{2}):(\\d{2}),(\\d{3})");
regex patron(".*");
smatch m;
while (getline(in, line)) {
if (regex_match(line, m, patron)) {
out << "ok";
};
out << line;
}
in.close();
out.close();
代碼總是在out.srt文件中打印字符串行,但從不在if(regex_match(line,m,patron))中輸入字符串「ok」。 01: 我有以下行
00測試它00708 - > 00:01:01800
你看看那條河
00:01:02,977 - > 00:01:04,706
輕輕地流過。
00:01:06213 - > 00:01:08238
你注意到葉
我們應該猜測你想要匹配什麼嗎? –
我想匹配註釋行,但不匹配任何行 –
@DiegoSilvera - 無法重現:使用您的代碼,所有行(空)也會生成一個「ok」 – max66