I need to check whether a string contains other than the specified words/sentence (javascript), it will return true if:
- it contains an alphabets, except this phrase:
ANOTHER CMD - it contains other than specified multiple sequence of numbers for example:
["8809 8805", "8806 8807"](the numbers are examples I should be able to test the string for any array of numbers)
Thank you!
>Solution :
you can try regex!
use your array of strings as the ‘|’ separated regex value
and check the specified string in the given line. if it presents negate the output.
const regex = /(ANOTHER CMD|8809 8805|8806 8807)/gi
console.log(!regex.test('Should not contain word ANOTHER CMD'))
Output
false