【发布时间】:2018-07-09 19:09:54
【问题描述】:
所以我的应用程序中有一个字符串,其中包含一个 html img 标签
<img src="imagsource.jpg" width="imageWidth" />
现在我想在两个不同的字符串中提取图像标签及其src 属性。所以我试图做的是:
QRegExp imageRegex("\\<img[^\\>]*src\\s*=\\s*\"([^\"]*)\"[^\\>]*\\>", Qt::CaseInsensitive);
int a = imageRegex.indexIn(description);
int b = a + imageRegex.matchedLength();
QString imgTag = description.mid(a,b); // this kind of works but doesn't return the img tag properly (extra information is included)
// how to obtain the "src" attribute, I have tried this: src\s*=\s*\"(.+?)" but it doesn't work
QString imgSrc = ??
我尝试查看有关如何使用正则表达式从其他字符串中提取字符串的其他帖子,我尝试在 QRegExp 中使用相同的模式,但它们似乎没有给出正确的结果。
【问题讨论】: