I need to match a value in a string by using regex pattern but I need to make the term as variable The code below is working.
for(const annt of result){
if (annt?.filename.match(/_V_1_.*/)) {
// do something
console.log('matched the file ' + annt.filename);
}
}
but I would like to pass the match term dynamically like below but it doesn't match. I am not sure what should I enclose the match_term with?
let match_term = '/_V_'+increment+'_.*/'; // /_V_1_.*/
for(const annt of result){
if (annt?.filename.match(match_term)) {
// do something
console.log('matched the file ' + annt.filename);
}
}