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

180
Views
¿Expresión regular de Javascript para buscar desde la letra inicial?

Quiero agregar la función de búsqueda. Necesito buscar cualquier documento por letra inicial.

Supongamos que tenemos algún documento como-

 Apple Industry Samsung Industry Xioami Industry Ahua Industry Sumatech Industry

Cuando el usuario busca un entonces debería dar el resultado que comienza con un me gusta-

 Ahua Industry Apple Industry

Puede ver el resultado mostrado en orden alfabético

Ya he creado una expresión regular como esta-

 { Industry: { '$regex': 'a', '$options': 'i' } }

Pero muestra todo el contenido que contiene a archivo .

Me gusta-

Muestra cada contenido porque todo el contenido contiene a archivo .

Como puedo solucionar eso. Alguien puede ayudarme.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe agregar el modificador startWith a su expresión regular. No estoy seguro de cómo este objeto se convierte a la expresión regular, pero aquí tienes:

 { Industry: { '$regex': '^a.*', '$options': 'i' } } 

 function matchText(query) { const text = ['Apple Industry', 'Samsung Industry', 'Xioami Industry', 'Ahua Industry', 'Sumatech Industry' ]; const regex = new RegExp(`^${query}.*`, 'i'); text.forEach((item) => console.log(item.match(regex))); } matchText('a'); matchText('ap');

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!