I need to check all elements of an array (strings) if they matches any regex, which is also stored in an array.
So here is the string-array and and regex array (in this example all three elements are the same regex - I know that doesn't make sence):
let array = [ 'just some', 'strings', 'which should be tested', 'by regex' ];
let regexes = [ /([^.]+)[.\s]*/g, /([^.]+)[.\s]*/g, /([^.]+)[.\s]*/g ];
Now I would do two _.each-loops like this:
_.each(array, function(element) {
_.each(regexes, function(regex) {
let match = regex.exec(element);
if (match && match.length)
doSomething(match);
});
});
But what I want to achieve is, that if only one regex is matching, I want to process this string. So with this senseless regexes-array, this would never be the case, as there would be no or three matching regex.
Furthermore I would like to knwo if it possible to avoid this nested each-loop.
Update
Example:
let array = [ '1. string', 'word', '123' ]
let regexes = [/([a-z]+)/, /([0-9]+)/]
array[0] should NOT pass the test, as both regex are matching
array[1] should pass the test, as just ONE regex is matching
array[2] should pass the test, as just ONE regex is matching
so only the result for array[1] and array[2] should be used for further processing doSomething(match)