By this method I want to use a variable in regex but it creates an extra / in the output:
var counter = 0,
    replace = "/\$" + counter;
    regex = new RegExp(replace);
    console.log(regex);
The output is /\/$0/ while I expected /\$0/, would you tell me what's wrong with it?
 
     
    