Javascript Regex: How to put a variable inside a regular expression? [duplicate]

So for example:

function(input){
    var testVar = input;
    string = ...
    string.replace(/ReGeX + testVar + ReGeX/, "replacement")
}

But this is of course not working 🙂
Is there any way to do this?

9 Answers
9

Leave a Comment