QRegExp Error
-
Hello,im cosufing about QRegExp from QSyntaxHighlight
this is my code of QREgExp:
rule.pattern = QRegExp("\d[0-9]\d");it give warning
myhighlighter.cpp:43:36: warning: unknown escape sequence '\d'i know what that mean but in doc.qt,io:
https://doc.qt.io/archives/qt-4.8/qregexp.htmlits say
Matches a digit,but why when i wrote it,it doesnt work -
@ELEMENTICY
We told you your original\dneeded to be\\d, because of C++ literal escape characters.Then you decided to try
//W, even though nowhere will have said to use that.Then @SGaist told you that you need
\\W, in the same way as\\d.So now you decide to ignore all of the above, go for
\W, and ask what it wrong.Have you understood anything about C++ escape character and regular expressions? It's important to under & learn from questions, not just bang bad stuff into code....
-
Hello,im cosufing about QRegExp from QSyntaxHighlight
this is my code of QREgExp:
rule.pattern = QRegExp("\d[0-9]\d");it give warning
myhighlighter.cpp:43:36: warning: unknown escape sequence '\d'i know what that mean but in doc.qt,io:
https://doc.qt.io/archives/qt-4.8/qregexp.htmlits say
Matches a digit,but why when i wrote it,it doesnt work@ELEMENTICY
Why are you usingQRegExp/archive doc for Qt 4.8? Are you stuck on Qt4?Meanwhile, think about
\inside literal C++ strings!QRegExp("\\d[0-9]\\d"); -
Hi,
Because while the regular expression itself is correct, the string is wrong. You need to escape the backslashes in it.
Unless you are locked to Qt 4, you should migrate to QRegularExpression as QRegExp has been deprecated and removed from Qt 6.
-
@ELEMENTICY
Why are you usingQRegExp/archive doc for Qt 4.8? Are you stuck on Qt4?Meanwhile, think about
\inside literal C++ strings!QRegExp("\\d[0-9]\\d");@JonB im using qt5+
-
@ELEMENTICY
Why are you usingQRegExp/archive doc for Qt 4.8? Are you stuck on Qt4?Meanwhile, think about
\inside literal C++ strings!QRegExp("\\d[0-9]\\d");@JonB oh thx i used two
\and its work,but i notice i dont want that effect.The one i wanna use is //W (need cap) which is Matches a non-word character.i used two
/and its not work,please help -
You want
\Wtherefore it's\\W. Why use forward slashes ? -
-
@ELEMENTICY
We told you your original\dneeded to be\\d, because of C++ literal escape characters.Then you decided to try
//W, even though nowhere will have said to use that.Then @SGaist told you that you need
\\W, in the same way as\\d.So now you decide to ignore all of the above, go for
\W, and ask what it wrong.Have you understood anything about C++ escape character and regular expressions? It's important to under & learn from questions, not just bang bad stuff into code....