按条件获取结果列表

问题描述

我想通过 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);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...