Search code examples
regexqtqregexp

Why doesn't this simple QRegExp match?


Very simply, here is test code which fails.

QRegExp BASIC_FORMAT ("^\\s*(.+?)\\s*,\\s*(.+)\\s*$");
QString test = "Catherine the Great, Szczecin 2/5/1729 to Saint Petersburg 17/11/1796";

qDebug ("%i", BASIC_FORMAT .indexIn (test));

This prints -1, although if I copy the strings into something like regex101.com (resolving double-backslashes myself, of course) then it matches as expected.

Why is QRegExp not matching in this case?


Solution

  • QRegExp does not support non-greedy quantifiers like +?

    You could use [^,]+ instead