获取by条件的结果列表



我想通过reg表达式的这个条件获得一个结果列表:

QRegExp rx(
"(https://)"
"(.*)"
"(\.jpg)"
);

QStringList list;
int pos = 0;

while ((pos = rx.indexIn("jpegData_https://sfasdfsf_sadlfkjnsdlfjhn.jpgasodjfhasdfoho;usdoauhfsvc.asdfkpjhttps://adfklja32908jf0jmn01.jpg", pos)) != -1)
{
list << rx.cap(0);
pos += rx.matchedLength();
}

for(auto it : list)
{
qDebug() << it;
}

我明白了:

"pegData_https://sfasdfsf_sadlfkjnsdlfjhn.jpgasodjfhasdfoho;usdoauhfsvc.asdfkpjhttps://adfklja32908jf0jmn01.jpg"

我需要得到:

  1. https://sfasdfsf_sadlfkjnsdlfjhn.jpg
  2. https://adfklja32908jf0jmn01.jpg

请帮帮我,QRegExp条件出了什么问题?

缺省情况下,匹配是贪婪的。你想要的行为应该是在你的QRegExp上调用setMinimal(true)。

QRegExp rx("(https://)(.*)(\.jpg)");
rx.setMinimal(true);