Tyler Jandreau
Tyler Jandreau

Reputation: 4335

QRegExp trouble matching pattern

I'm attempting to match strings with QRegExp in a callback function. I'm using the C++ implementation of Qt. I've written a regular expression of the form: Atmospheres.(\\d+).(latitude|longitude|radius|path) and verified it here

The problem is, matching the regular expression with QRegExp is always returning a -1, a non-match.

Here is some code:

QString name = "Atmospheres.1.latitude";
QRegExp regex("Atmospheres.(\\d+).(latitude|longitude|radius|path)");

int pos = 0;
regex.indexIn(name, pos); 

The above line always returns -1. Any suggestions? Thank you.

Upvotes: 1

Views: 427

Answers (1)

tumdum
tumdum

Reputation: 2031

Are you sure that you are running this exact code? It works fine for me:

#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;
}

executing this produces:

5.2.0: 0

Upvotes: 2

Related Questions