C++ 增强正则表达式不保存捕获
C++ Boost Regex doesn't save capture
我正试图与一个网页通信,检索它的源代码,然后搜索和存储特定的字符串(名称)内的输出文件。以下是我所做的:
#include <iostream>
#include <string>
#include <conio.h>
#include <boost/asio.hpp>
#include <boost/regex.hpp>
#include <fstream>
using namespace std;
ofstream o("out.txt");
int main()
{
boost::asio::ip::tcp::iostream s("www.lolsummoners.com", "http");
if(!s)
cout << "Could not connect to http://www.lolsummoners.com/n";
s << "GET /ladders/eune HTTP/1.1rn"
<< "Host: www.lolsummoners.comrn"
<< "Accept: */*rn"
<< "Connection: closernrn" ;
boost::regex rgx("/leagues/.*>(.+\s*)</a></td>");
for(string line; getline(s, line); )
{
boost::smatch matches;
if(regex_search(line, matches, rgx ) )
{
o << matches[0] << 'n';
}
}
}
问题是,在我的输出文件中,它不保存捕获,相反,它保存了整个内容:
/leagues/eune/64657">Kenachi</a></td>
我只想保存"Kenachi"
没有"
matches[0]
是整个匹配表达式。
第一个捕获组在matches[1]
相关文章:
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 无法将结构注册为增强几何体3D点
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 在C++中将类(带有Vector成员)保存为二进制文件
- C++.我想将更改后的特定字符行保存在字符串中
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 将RGB图像保存为PPM格式
- 哈希文件递归并保存到矢量Cryptopp中
- 如何将二进制格式的 C++ 对象的 std::vector 保存到磁盘?
- 无法通过头文件保存变量的值
- 增强基于 XML class_id的反序列化
- 我们可以将数据永久保存为数据结构吗?
- 增强精神解析器规则以检测语句中的特殊结尾
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 增强将未定义的映射保存到磁盘的能力
- C++ 增强正则表达式不保存捕获