I'd like to find out how often and if a certain pattern in a certain programming language is used.

In my case - I'd like to find out how many/if people do eval("/"+regexString+"/") in JavaScript and/or compose regular expressions from strings using /.

Typically, I perform a GitHub search - I did this when working on a feature in the past, and it was for a much smaller API with a clear function call and a smaller scoped use case - doing this manually doesn't seem practical here.

I'm doing this in order to characterise an API I'm working on and I'm considering whether or not this is something people do in order to provide a better and more consistent API..

  • How can I research how common this pattern is?

(I'd appreciate answers based on science and known practices)

1 Answer 1


You might want to search for Javascript static program analysis tools (like this question), e.g. Flow. You'll find many research papers on that subject.

I've heard several talks on that subject, and IIRC eval is used, sometimes carelessly or needlessly, in many practical Javascript software.

Your question can be understood in two different ways:

How often is eval("/"+regexString+"/") statically appearing in various Javascript source code?

How often is eval("/"+regexString+"/") dynamically executed in some given application?

You could hack some existing Javascript implementation to detect such patterns.

Notice that if regexString is a single line string starting with a / character, eval("/"+regexString+"/") is evaluating a comment!

Don't forget the halting problem & Rice's theorem; hence, static program analysis can never be entirely satisfactory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.