Dodaj zmienną wewnątrz Regex w JavaScript
var pattern="cd"
var repeats=3
new RegExp(`${pattern}{${repeats}}`, "g")
Calm Cardinal
var pattern="cd"
var repeats=3
new RegExp(`${pattern}{${repeats}}`, "g")
// CREATE A REGEXP object
var replace = "regex";
var re = new RegExp(replace,"g");
//then use
"mystring".replace(re, "newstring")