let regex = '/year B.Tech sem Sem/g'; let year = 'II'; let sem = 'I'; regex = regex.replace('year',year); regex = regex.replace('sem',sem); console.log(regex) // here the output is = /II B.Tech I Sem/g regex = new RegExp(regex); console.log(regex) // here the regex changes and the output = /\/II B.Tech I Sem\/g/
let year = 'II'; let sem = 'I'; let regex = new RegExp(`${year} B.Tech ${sem} Sem`, "g");
RegExp
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)