It would be nice if clazy could validate regular expressions passed in text form to QRegExp or QRegularExpression. This should be either done by trying to parse/compile the regular expression passed to either class or by checking the passed regular expression for common mistakes (see examples below) based on context-sensitive text patterns rather than compiling the expression. Example for which clazy should warn (passing raw char* to constructors to keep examples brief): QRegularExpression("\bA"); // should be \\bA QRegExp("v\\d([.]\\d)*)"); // mismatching parentheses
we could use a regular expression to validate regular expressions :)
One option is to link to pcre or Qt and validate the string. Additionally, I think it should warn if you're not using C++11 raw-string-literals, which makes code much less error prone.
(In reply to Sergio Martins from comment #2) > One option is to link to pcre or Qt and validate the string. Using pcre would have the advantage of being a 'lighter' dependency than Qt and maybe more generally already installed. Using Qt would have the advantage to be more 'realistic'. > Additionally, I think it should warn if you're not using C++11 > raw-string-literals, which makes code much less error prone. If it would be technically possible, make the dependency on pcre or Qt compile-time optional, i.e. a configuration/build flag. Coded in clazy could be some basic checks that would be applied before any pcre/Qt tests and be available even if pcre/Qt support would be disabled. Those basic checks could be: - Correct usage of raw-string literals as you mention, e.g. \b vs \\b - Correct matching of parenthesises: (..[..]{..}..) with some support for special cases such as \( or [^{] ... in general some quick and dirty checks for common mistakes and always cheaper than parsing the regexp in pcre or Qt. For more inspiration check StackExchange for common problems programmers have with regexps ... ;-)