CodeQL library for JavaScript

Member predicate RegExpTerm::isUsedAsRegExp

Holds if this term is part of a regular expression literal, or a string literal that is interpreted as a regular expression.

Unlike isPartOfRegExpLiteral and isPartOfStringLiteral, this predicate takes data flow into account, to exclude string literals that aren’t used as regular expressions.

For example:

location.href.match("^https://example\\.com/") // YES - String is used as regexpp

console.log("Hello world"); // NO - string is not used as regexp

/[a-z]+/g; // YES - Regexp literals are always used as regexp
predicate isUsedAsRegExp()