我试图在回调函数中将字符串与QRegExp匹配。我正在使用C++实现的Qt。我编写了一个表单的正则表达式:Atmospheres.(\\d+).(latitude|longitude|radius|path),并验证了它的这里
问题是,将正则表达式与QRegExp匹配总是返回一个不匹配的-1。
以下是一些代码:
QString name = "Atmospheres.1.latitude";
QRegExp regex("Atmospheres.(\\d+).(latitude|longitude|radius|path)");
int pos = 0;
regex.indexIn(name, pos); 上面的行总是返回-1。有什么建议吗?谢谢。
发布于 2014-01-20 20:18:29
您确定您正在运行此代码吗?对我来说很好:
#include <iostream>
#include <QString>
#include <QRegExp>
int main()
{
QString name = "Atmospheres.1.latitude";
QRegExp regex("Atmospheres.(\\d+).(latitude|longitude|radius|path)");
int pos = regex.indexIn(name, 0);
std::cerr << QT_VERSION_STR << ": " << pos << std::endl;
return 0;
}执行此操作将产生以下结果:
5.2.0: 0https://stackoverflow.com/questions/21243218
复制相似问题