【发布时间】:2011-11-10 08:49:00
【问题描述】:
我正在尝试使用 boost 正则表达式从文本文件中提取子匹配项。目前我只返回第一个有效行和整行而不是有效的电子邮件地址。我尝试使用迭代器并使用子匹配,但我没有成功。这是当前代码:
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();
}
【问题讨论】: