Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Matching a regular expression in string.
NIXIN last edited by NIXIN
I am trying something like below,
int main(int argc, char *argv)
QCoreApplication a(argc, argv);
QString str = "((Hello1 and Hello2) in Hello.World)";
QString matchWord = "Hello;
qDebug() << str.contains(QRegExp("\\b" + matchWord + "\\b"));
I am getting output as true. I want to what's wrong??
My intention is to match only a complete word, like "Hello".
Can anyone help me with this?
I think the engine matches the "Hello.World", treating the dot (.) as a word boundary.
You can check where the match happened using QRegExp API to be sure.
BTW. It is recommended to use QRegularExpression in Qt5 - QRegExp is just a leftover from Qt4 times.
NIXIN last edited by
can you provide a small piece of code
Sure, they are in the docs: http://doc.qt.io/qt-5/qregexp.html#code-examples
indexIn() method should interest you in this case.