The doc of QRegExp::escape didn't mention backslash
-
Recently our colleague sent me a code review and it's basically about escaping all special characters except for "?" and "*" since we only allow users to use wildcards but our engine uses regex. I saw the code didn't escape backslash characters and he said he took QRegExp::escape documentation description as a reference:
Returns the string str with every regexp special character escaped with a backslash. The special characters are $, (,), *, +, ., ?, [, ,], ^, {, | and }.
But after trying to feed
\
toQRegExp::escape
we found it actually escapes it! We can also see it does escape it in the Qt source code. So I guess the doc should be fixed, but I don't know where I should report this issue so I'm going to raise the concern here. -
Recently our colleague sent me a code review and it's basically about escaping all special characters except for "?" and "*" since we only allow users to use wildcards but our engine uses regex. I saw the code didn't escape backslash characters and he said he took QRegExp::escape documentation description as a reference:
Returns the string str with every regexp special character escaped with a backslash. The special characters are $, (,), *, +, ., ?, [, ,], ^, {, | and }.
But after trying to feed
\
toQRegExp::escape
we found it actually escapes it! We can also see it does escape it in the Qt source code. So I guess the doc should be fixed, but I don't know where I should report this issue so I'm going to raise the concern here.@sc420
Hello and welcome.You raise a reasonable point. However, since you are using
QRegExp
are you aware that this is no longer a part of Qt6 going forward, it is only in Qt 5 Core Compatibility APIsThe Qt 5 Core Compat module contains the Qt 5 Core APIs that were removed in Qt 6. The module facilitates the transition to Qt 6.
Given which they may not be so interested in updating documentation. On your side, are you aware that at some point this may be phased out and you ought think about moving on?
If you do wish to report this documentation issue you are welcome to do so at https://bugreports.qt.io/
-
Recently our colleague sent me a code review and it's basically about escaping all special characters except for "?" and "*" since we only allow users to use wildcards but our engine uses regex. I saw the code didn't escape backslash characters and he said he took QRegExp::escape documentation description as a reference:
Returns the string str with every regexp special character escaped with a backslash. The special characters are $, (,), *, +, ., ?, [, ,], ^, {, | and }.
But after trying to feed
\
toQRegExp::escape
we found it actually escapes it! We can also see it does escape it in the Qt source code. So I guess the doc should be fixed, but I don't know where I should report this issue so I'm going to raise the concern here.[EDIT: @JonB beat me to it! --JKSH]
Hi, and welcome!
@sc420 said in The doc of QRegExp::escape didn't mention backslash:
So I guess the doc should be fixed, but I don't know where I should report this issue so I'm going to raise the concern here.
Thank you for reporting this. In general, the best place to report issues (including documentation issues) is https://bugreports.qt.io/
In this particular case though, QRegExp is deprecated so the doc fix will be very low priority. We highly recommend porting to QRegularExpression instead, which has been available since Qt 5.0: https://doc.qt.io/qt-6/qregexp.html#porting-to-qregularexpression
-