Qt QRegularExpression如何获取最后匹配的单词

Qt QRegularExpression如何获取最后匹配的单词,qt,qregularexpression,Qt,Qregularexpression,(?i)时间.([0-9::]+)-此模式查找所有文本-时间=00:00:00.00 如何在第一个或第二个文本中获取最后一个匹配的元素(time=00:05:01.84) 第一段案文: Metadata: creation_time : 2013-11-21 11:03:11 handler_name : IsoMedia File Produced by Google, 5-11-2011 Output #0, mp3, to 'ssdad.mp3': M

(?i)时间.([0-9::]+)-此模式查找所有文本-时间=00:00:00.00

如何在第一个或第二个文本中获取最后一个匹配的元素(time=00:05:01.84)

第一段案文:

Metadata:
      creation_time   : 2013-11-21 11:03:11
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
Output #0, mp3, to 'ssdad.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    TSSE            : Lavf54.63.104
    Stream #0:0(und): Audio: mp3, 44100 Hz, stereo, fltp
    Metadata:
      creation_time   : 2013-11-21 11:03:11
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> libmp3lame)
Press [q] to stop, [?] for help
size=    3779kB time=00:03:01.84 bitrate= 128.0kbits/s
size=    3779kB time=00:04:01.84 bitrate= 128.0kbits/s
size=    3779kB time=00:05:01.84 bitrate= 128.0kbits/s
video:0kB audio:3779kB subtitle:0 global headers:0kB muxing overhead 0.008011%
第二个文本:

Metadata:
      creation_time   : 2013-11-21 11:03:11
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
Output #0, mp3, to 'ssdad.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    TSSE            : Lavf54.63.104
    Stream #0:0(und): Audio: mp3, 44100 Hz, stereo, fltp
    Metadata:
      creation_time   : 2013-11-21 11:03:11
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> libmp3lame)
Press [q] to stop, [?] for help
size=    3779kB time=00:05:01.84 bitrate= 128.0kbits/s
video:0kB audio:3779kB subtitle:0 global headers:0kB muxing overhead 0.008011%

要使用
QRegularExpression
获取最后一个匹配的元素,可以使用获取
QRegularExpressionMatchIterator
并将其迭代到最后一个元素:

QString getLastTime(const QString &input)
{
    auto re = QRegularExpression { R"((?i)time.?([0-9:]+))" };
    auto matchIterator = re.globalMatch(input);
    while(matchIterator.hasNext())
    {
        auto result = matchIterator.next();
        if (!matchIterator.hasNext())
        {
            return result.captured(0);
        }
    }
    return QString{};
}
或者,您可以与
QRegularExpression
一起使用以获取最后一个匹配项:

QString getLastTime2(const QString &input)
{
    auto match = QRegularExpressionMatch{};
    input.lastIndexOf(QRegularExpression { R"((?i)time.?([0-9:]+))" }, -1, &match);
    return match.captured(0);
}