C++ Primer(第5版) 练习 17.17
练习 17.17 更新你的程序,令它查找输入序列中所有违反"ei"语法规则的单词。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块:
/*************************************************************************
> File Name: ex17.17.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 theif receive";
smatch results;
regex r(pattern, regex::icase);
for(sregex_iterator it(text.begin(), text.end(), r), end_it; it != end_it; ++it){
cout<<it->str()<<endl;
}
return 0;
}