I am trying to create a Regular Expression from code. Basically taking a code snippet (even if it is only a part of a line) and search for an exact match in a code base. I am using RegExp to create a regular expression that I pass to another function. An example:
let codeSnippet = new RegExp("let value = myFunc('something')");
This works great. However, it seems that if there is something unterminated in the code, then I can't make a RegExp from it. So this doesn't work:
let codeSnippet = new RegExp("let value = myFunc('someth");
I want to have a RegExp that is exactly what is passed in, as I am trying to match exactly. I am getting this error:
SyntaxError: Invalid regular expression: /let myfunc(\"some/: Unterminated group
How can I create a RegExp that is just exactly what is entered, no matter what?