小编Joh*_*ohn的帖子

在c ++中使用boost regex提取子匹配

我正在尝试使用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)

c++ regex boost

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

boost ×1

c++ ×1

regex ×1