C++ Primer(第5版) 练习 17.18
练习 17.18 修改你的程序,忽略包含"ei"但并非拼写错误的单词,如"albeit"和"neighbor"。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块:
> File Name: ex17.18.cpp> Author: > Mail: > Created Time: Sun 18 Aug 2024 09:09:23 AM CST************************************************************************/#include<iostream>
#include<regex>
using namespace std;int main(){string pattern("[^c]ei");pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";string text = "receipt freind albeit theif neighbor receive";smatch results;regex r(pattern, regex::icase);for(sregex_iterator it(text.begin(), text.end(), r), end_it; it != end_it; ++it){if(it->str() == "albeit" || it->str() == "neighbor"){continue;}cout<<it->str()<<endl;}return 0;
}
运行结果显示如下:
