I must replace the QRegExp
with QRegularExpression
, and I had the check for “a string contains only white space characters” working, but I don’t know how to set QRegularExpression
to do the same thing. Here is a sample code (in comments, I put the result – and the desired result).
#include <QCoreApplication>
#include <QDebug>
#include <QRegExp>
#include <QRegularExpression>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString inputString1 = "thisisatest";
QString inputString2 = "this is a test";
QString inputString3 = " nt";
// How do I make this work the same as QRegExp ?
QRegularExpression whiteSpace(QStringLiteral("\s*"));
qDebug() << whiteSpace.match(inputString1).hasMatch(); // Weird !!! says true. Should be false
qDebug() << whiteSpace.match(inputString2).hasMatch(); // Says true. Should be false
qDebug() << whiteSpace.match(inputString3).hasMatch(); // I only want this to be true
// This is the old behavior that I want to keep
QRegExp whiteSpace1(QStringLiteral("\s*"));
qDebug() << whiteSpace1.exactMatch(inputString1); // False
qDebug() << whiteSpace1.exactMatch(inputString2); // False
qDebug() << whiteSpace1.exactMatch(inputString3); // True
return 0;
}