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

174
Vistas
MongoDB RegEx not finding any results when string contains parenthesis

When using regex to allow for case insensitivity, it only works for plain strings. The db query returns no results when parenthesis or other special characters are used for the name.

Example: "Push It" will work fine and return songs. However when searching "Escape (The Pina Colada Song)", it returns no songs. How can I make the Regex allow for these special characters?

Any suggestions would be great.

const lowercaseName = new RegExp(`^${name}`, 'i')
const songs: any = await Song.find({ name: lowercaseName, artist_id })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should escape all the special characters in the string that you are sending. Try this:

const lowercaseName = new RegExp(`^${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'i')
const songs: any = await Song.find({ name: lowercaseName, artist_id })
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