Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda