Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
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!

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Yes you can replace all not in the array

const arr = ["ANOTHER CMD","8809 8805", "8809 8805"]
const okContent = str => { 
  arr.forEach(entry => str = str.replaceAll(entry,""))
  return str.trim()==="";
};

console.log(okContent('Has other stuff than ANOTHER CMD and 8809 8805'))
console.log(okContent('8809 8805 ANOTHER CMD 8809 8805'))

about 4 years ago · Juan Pablo Isaza Report

0

I don't know if it's the correct way of doing it but this worked for me:

  • replace all the valid words with balnk (using replace)
  • check if the string is left empty
  • if it's empty, it means that the string does not contain any unwanted string (to check for space you could use trim method)
about 4 years ago · Juan Pablo Isaza Report

0

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)/i
console.log(!regex.test('Should not contain word ANOTHER CMD'))

console.log(regex.test('Should contain word ANOTHER CMD'))

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!