使用QRegExp从URL中提取文件名
Extracting the filename off a URL with QRegExp
我有一个问题,我有一个RegEx, [^/&?]+.w{3,4}(?=([?&].*$|$)),但我不能让它与下面的[1]函数一起工作。
[1] - http://doc.qt.io/qt-5/qregexp.html
这是我试过的代码:
QRegExp rx("[^/\\&\?]+\.\w{3,4}(?=([\?&].*$|$))", Qt::CaseInsensitive, QRegExp::RegExp);
std::ostringstream list;
int pos = 0;
while ((pos = rx.indexIn(url, pos)) != -1) {
list << rx.cap(1).toStdString();
pos += rx.matchedLength();
}
return list;
它应该从URL中提取文件名,但只返回什么。我不知道哪里出了问题。有人能帮忙吗?
Qt有QUrl
类解析URL等。还有QUrl::fileName方法:
QUrl url("http://qt-project.org/support/file.html");
// url.adjusted(RemoveFilename) == "http://qt-project.org/support/"
// url.fileName() == "file.html"
相关文章:
- 从命令行c++发送文本文件名
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么istream不支持右值提取
- 为什么文件名被设置为一个点,而不是在读取矢量中的文件名时
- 如何设置一个范围来提取我想要获得的信息
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 视觉工作室项目.提取源文件夹名称
- C++17 - 使用自定义分配器的节点提取/重新插入 - 适用于 clang++/libc++,但不适用于 libstd
- 从 C++ 中的文件路径中提取文件名
- 使用boost::filesystem和boost::lexical_cast从文件名中提取数字
- 从文件名中提取文件名,路径来自参数
- 提取所有文件名 - 查找第一个文件
- 提取具有给定后缀的文件名部分C++
- 从路径中提取文件名
- 提取文件名的子字符串
- 从文件名中提取数字
- 使用QRegExp从URL中提取文件名
- 如何从文本文件中提取扩展名为.txt的文件名