Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check whether string contains other than specific word

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading