Is there a way in JavaScript to get Boolean value for a match of the string against the array of regular expressions?
The example would be (where the \'if\' statemen
You could use .test() which returns a boolean value when is find what your looking for in another string:
var thisExpressions = [ '/something/', '/something_else/', '/and_something_else/'];
var thisString = new RegExp('\\b' + 'else' + '\\b', 'i');
var FoundIt = thisString.test(thisExpressions);
if (FoundIt) { /* DO STUFF */ }
Consider breaking this problem up into two pieces:
filter
out the items that match
the given regular expression0
matches in itconst sampleStringData = ["frog", "pig", "tiger"];
const matches = sampleStringData.filter((animal) => /any.regex.here/.test(animal));
if (matches.length === 0) {
console.log("No matches");
}