遇到正则匹配,暂时记录一下
匹配出符合规则的所有字符串,现在还没弄清楚怎么不保留标识字符,如“1(.)3”在输出时没有‘1’与‘3’
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main()
{
string str = "abc123aa236a612ad1b3s1 3";
regex re("1(.)3");
sregex_iterator sre(str.begin(),str.end(),re),end;
while (sre!=end){
cout << sre->str() << endl;//符合规则的字符串
cout << sre->position() << endl;//起始位置
sre++;
}
system("pause");
return 0;
}
/*运行结果
123
3
1b3
17
1 3
21
*/