我正在尝试使用boost regex从文本文件中提取子匹配.目前我只返回第一个有效行和整行,而不是有效的电子邮件地址.我尝试使用迭代器并使用子匹配但我没有成功.这是当前的代码:
if(Myfile.is_open()) {
boost::regex pattern("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$");
while(getline(Myfile, line)) {
string::const_iterator start = line.begin();
string::const_iterator end = line.end();
boost::sregex_token_iterator i(start, end, pattern);
boost::sregex_token_iterator j;
while ( i != j) {
cout << *i++ << endl;
}
Myfile.close();
}
Run Code Online (Sandbox Code Playgroud)