Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Getting Litterals ., + and - in a QRegExp
I have this humongous regular expression to express any positive integer or real number (I tested it on http://regexr.com/):
My question is: how do I make this into a valid QRegExp? Using it as above is not accepted as Qt complains that ., + and - are not recognized as valid escape sequences...
Are you locked to QRegExp ? It has been deprecated. QRegularExpression would be more suited.
As for your question, you need to escape them using two backslashes.
Thanks! The extra backslashes work :)
I was not aware of QRegularExpression. I just tried to use it but there seems to be no replacement for QRegExpValidator, which I need as argument for QLineEdit::setValidator. Or am I missing something?
Do you mean the QRegularExpressionValidator ?
Yes, that's what I missed. Thanks! I will use QRegularExpression instead of QRegExp :)