JSFiddle - React, Tailwind, and code Playground
JavaScript
var txt = "Completely irrelevant text line, featuring ducks and Wolves.";
// First try, catch regular expressions from an array
var arrayRegExp = ["/wolves/i", "/Duck/"];
for (var e = 0; e < arrayRegExp.length; e++) {
var rge1 = txt.match(new RegExp(arrayRegExp[e]));
/*
I assume the problem lies in the fact that RegExp object
gets fed with: "/wolves/i" instead of: /wolves/i
*/
if (rge1) {
return document.write("First method: {" + rge1[0] + "}")
}
}
// Second try, this time use separate variables
var regexp1 = /wolves/i;
var regexp2 = /Duck/;
var rge2 = txt.match(new RegExp(regexp1))
if (rge2) {
document.write("Second method: {" + rge2[0] + "}")
}