163
rated 0 times
[
170]
[
7]
/ answers: 1 / hits: 15493
/ 7 Years ago, sat, june 17, 2017, 12:00:00
I'm trying to make a function that finds the string that contains all words from an array.
I have tried this:
function multiSearchOr(text, searchWords){
var searchExp = new RegExp(searchWords.join(|),gi);
return (searchExp.test(text))?Found!:Not found!;
}
alert(multiSearchOr(Hello my name sam, [Hello, is]))
But this only alert Found when one of the words have been found.
I need it to alert me when all the words are in the string.
An example:
var sentence = I love cake
var words = [I, cake];
I want the application to alert me when it finds all of the words from the array in the string sentence. Not when it only found one of the words.
More From » regex