Matching a regular expression in string.
-
wrote on 30 Nov 2016, 09:54 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"));
return a.exec();
}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.
-
wrote on 30 Nov 2016, 10:19 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.
4/4