C++的正则封装的不丰富.只有最基础的三个主要的函数(也可能是我孤陋寡闻).要有更为丰富的功能需要自己进一步组合.
我目前只需要循环查找这个功能,并且我也不知道c++的正则支持正则的哪些功能;
代码如下,后面要用到其他的诸如替换之类的功能在来补充
#include<iostream>
#include<string>
#include<regex>
#include<Windows.h>
using namespace std;
int main(void)
{
string s = "The operation to complete";
regex r("\\b\\w+?\\b"); //字符串构造有点不一样.
smatch m; //是个容器.
while (regex_search(s, m, r))
{
cout << m.str() << endl;
s = m.suffix().str(); //关键,实现循环查找的重要步骤.
}
system("pause");
return 0;
}
输出:

原文:https://www.cnblogs.com/love-DanDan/p/10700508.html