1// CREATE A REGEXP object
2var replace = "regex";
3var re = new RegExp(replace,"g");
4//then use
5"mystring".replace(re, "newstring")
1var pattern="cd"
2var repeats=3
3new RegExp(`${pattern}{${repeats}}`, "g")
4
1function alphabet(str) {
2 let alphabetStr = 'abcdefghijklmnopqrstuvwxyz';
3 let strRegEx =`[${str[0]}-${str[3]}]`; //set regex with variables
4 let newRegEx = new RegExp(strRegEx, 'g'); //create new regex object
5 //regex object pattern is: RegExp(pattern, modifiers)
6 let charSetStr = alphabetStr.match(newRegEx);
7 return charSetStr;
8}
9
10console.log(alphabet('abce'));
11//expected [ 'a', 'b', 'c', 'd', 'e' ]