qt中的正则是不匹配字符串

Regex in Qt not matching string it should

本文关键字:不匹配 字符串 qt      更新时间:2023-10-16

所以我有一个函数,让我们称其为getMatch。我写了一条以匹配它收到的字符串,但QT Regex引擎不像我期望的那样匹配。

为了演示,这是一些代码:

bool getMatch()
{
    QString item = "BitwiseAND(Value, Mask)";
    QRegExp rx("\w+\([\w+,\s]+?\)", Qt::CaseInsensitive);
    return rx.exactMatch(item);
}

这应该每次都返回true,但它返回false。

我已经在在线测试人员中测试了正则表达式,应该没关系。

我认为您想要的是:

\w+\((\w+(?:,\s)?)+\)

您的正则是使用[而不是(,但这是一个字符类,而您正在做的只是分组和量化。。