diff --git a/ql/src/queries/style/RegexpInsteadOfPattern.ql b/ql/src/queries/style/RegexpInsteadOfPattern.ql new file mode 100644 index 00000000000..69541ed30eb --- /dev/null +++ b/ql/src/queries/style/RegexpInsteadOfPattern.ql @@ -0,0 +1,34 @@ +/** + * @name RegexpInsteadOfPattern + * @description The `matches` builtin predicate takes a special pattern format as an input, not a regular expression. + * @kind problem + * @problem.severity warning + * @id ql/rexexp-pattern + * @precision medium + */ + +import ql + +/** + * Gets a regular expression pattern that matches the syntax of likely regular expressions. + */ +private string getALikelyRegExpPattern() { + result = "/.*/[gimuy]{1,5}" or // pattern with at least one flag: /foo/i + result = "/\\^.*/[gimuy]{0,5}" or // pattern with anchor: /^foo/ + result = "/.*\\$/[gimuy]{0,5}" or // pattern with anchor: /foo$/ + result = "\\^.*\\$" or // pattern body with anchors: ^foo$ + result = ".*(?