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

164
Vistas
Searching through array of strings to match a keyword string that contains wildcard letters in Javascript?

I have a keyword string that contains at least 1 wildcard letter; "?". Each "?" represents a single lowercase letter between a-z. I need to search through an array of strings to find which letters match the keyword.

let input = ["happy", "have", "harvest", "harmonica"]

let keyword = "ha???"

result = "happy"

I've tried to replace the wildcard letter ? with regex, but it does not seem to work because it would return "ha/([a-z])+/g" and would not compare like I wanted it to.

I also tried to just replace ? with "", but obviously it would match all of the items so it doesn't work.

Is there any suggestions?

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

0

You could just replace ? with [a-z], and add start and end of string anchors (^ and $) to your regex. For example:

const input = ["happy", "have", "harvest", "harmonica"]

const keyword = "ha???"

const regex = new RegExp('^' + keyword.replace(/\?/g, '[a-z]') + '$')

const result = input.filter(w => regex.test(w))

console.log(result)

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