【问题标题】:Port QRegExp::exactMatch() in Qt6Qt6 中的端口 QRegExp::exactMatch()
【发布时间】:2021-10-05 04:25:24
【问题描述】:

我正在将 Qt5 应用程序移植到 Qt6。我想尽快离开 Qt6 的 Qt5CoreCompat 模块。我的问题是 QRegExp 类应该替换为 QRegularExpression 类。大多数补丁都比较简单,但我如何在 Qt6 中移植QRegExp::exactMatch()。以下是应用程序中的一些代码:

QRegExp version(QLatin1String("(.+)_v(\\d+)"));
if (version.exactMatch(completeBaseName/*QString*/))
{
        // some code
}

我在QRegularExpressionMatch 类中看不到这样做的方法。我想解决方案可能是这样的:

QRegularExpression version(QLatin1String("(.+)_v(\\d+)"));
QRegularExpressionMatch match = version.match(completeBaseName);
if (match.hasMatch())
{
        // Find exact match or not
}

我想要和以前一样的行为。

【问题讨论】:

    标签: c++ qt qt6


    【解决方案1】:

    文档建议使用anchoredPattern helper function 从正则表达式本身进行锚定:

    QRegularExpression version(QRegularExression::anchoredPattern(QLatin1String("(.+)_v(\\d+)")));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2022-01-20
      • 2021-12-12
      • 2021-11-20
      • 1970-01-01
      • 2021-12-21
      相关资源
      最近更新 更多