Answer the question
In order to leave comments, you need to log in
Reg.test() - how to check if certain words are required?
How to use a regular expression (one) to check if certain words are present in a string? That is, replace the following:
if(
/слово1/.test(string) &&
/слово2/.test(string) &&
/слово3/.test(string)
)
done()
Answer the question
In order to leave comments, you need to log in
let words = ['набор', 'определенных', 'слов'];
let Reg = new RegExp(words.map(word => `.*(?=${word})`).join(''), 'i');
let text1 = 'какойто текст и набор определенных слов';
let text2 = 'какойто текст определенных слов';
Reg.test(text1);
// true
Reg.test(text2);
// false
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question