I tried to rewrite the method (part of tutorial on w3schools).
The problem is to make a variable string to become part of the regular expression.
Tutorial Sample code:
function myFunction() {
var str = "The rain in SPAIN stays mainly in the plain";
var res = str.match(/ain/gi);
console.log(res)
}
I tried:
function myFunction() {
var str = "The rain in SPAIN stays mainly in the plain";
var test = "ain";
var re = "/"+test+"/gi";
var res = str.match(re);
console.log(res);
}
The way I tried did not work.