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

100
Views
MongoDB RegEx no encuentra ningún resultado cuando la cadena contiene paréntesis

Cuando se usa regex para permitir la insensibilidad a mayúsculas y minúsculas, solo funciona para cadenas simples. La consulta db no devuelve resultados cuando se utilizan paréntesis u otros caracteres especiales para el nombre .

Ejemplo: "Push It" funcionará bien y devolverá canciones. Sin embargo, al buscar "Escape (The Pina Colada Song)", no devuelve ninguna canción. ¿Cómo puedo hacer que Regex permita estos caracteres especiales?

Cualquier sugerencia seria genial.

 const lowercaseName = new RegExp(`^${name}`, 'i') const songs: any = await Song.find({ name: lowercaseName, artist_id })
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe escapar todos los caracteres especiales en la cadena que está enviando. Prueba esto:

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