To match string against the array of regular expressions with JavaScript, we use the some
method.
For instance, we write
const regexList = [/apple/, /pear/];
const text = "banana pear";
const isMatch = regexList.some((rx) => rx.test(text));
to call regexList.some
with a callback that calls rx.test
with text
to check if text
matches any of the regexes in regexList
.