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

171
Views
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 answers
Answer question

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 Report

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