Answers for "add variable inside regex in javascript"

6

javascript use variable regex

// CREATE A REGEXP object
var replace = "regex";
var re = new RegExp(replace,"g");
//then use
"mystring".replace(re, "newstring")
Posted by: Guest on September-11-2020
2

add variable inside regex in javascript

var pattern="cd"
var repeats=3
new RegExp(`${pattern}{${repeats}}`, "g")
Posted by: Guest on December-16-2020

Code answers related to "add variable inside regex in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language