Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
JavaScript search using includes method in js with exact match

Here is my code and the problem is whether you search for "remember" or "member" it returns the result.As 'remember' has 'member' and I just want to search for exact matches. I should not return anything when I search for 'member'.

txt= `38
00:04:17.795 --> 00:04:23.551
Two previous cases
were open and shut.

39
00:04:23.601 --> 00:04:29.140
It was January 3, 1995,
my daughter's birthday.

40
00:04:29.140 --> 00:04:30.441
I remember.`

const searchedWord = 'member';
var res = txt
  .toLowerCase()
  .split('\n\n')
  .filter((x) => {
    return x.includes(searchedWord.toLowerCase());
  });

console.log(res);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It sounds like you want to require word breaks on either side of the word you're searching for. You can do that with a regular expression:

const searchRegex = /\bmember\b/i; // ***
var res = txt
  .toLowerCase()
  .split('\n\n')
  .filter((x) => {
    return searchRegex.test(x);    // ***
  });

Live Example:

const txt = `38
00:04:17.795 --> 00:04:23.551
Two previous cases
were open and shut.

39
00:04:23.601 --> 00:04:29.140
It was January 3, 1995,
my daughter's birthday.

40
00:04:29.140 --> 00:04:30.441
I remember.

41
He was a member of the club

42
Something else`;

const searchRegex = /\bmember\b/i;
var res = txt
  .toLowerCase()
  .split('\n\n')
  .filter((x) => {
    return searchRegex.test(x);
  });

console.log(res);

If you need to create the regular expression dynamically (that is, starting with a string variable or similar containing "member"), see this question's answers and, if relevant, this one's.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda