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

172
Visualizações
Search for full word instead of part inside of it

I'm trying to find exact word in text user is sending, but obviously, when I'm trying to use message.content.includes(), it's also looking for parts of the word in text which I don't need! Any way to search by full words only?

Few examples: **TexT**, HeLlO, etc.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Yes, you can use a regex like this, assuming wordToFind holds the word you are searching for:

// Create regex from word with \b at each end which
// means "word boundary", and the 'i' option means
// case-insensitive
const wordSearch = new RegExp(`\b${wordToFind}\b`, 'i');

// Use the regular expression to test the content:
const hasWord = wordSearch.test(message.content);

// will be true if whole word is found

about 4 years ago · Juan Pablo Isaza Relatório

0

Put your content in to an array, splitting words if it's a piece of text. Array.includes will match whole words.

So either use [content].includes(word) if content is a single word, or content.split(' ').includes(word) if content is multiple words.

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