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

202
Views
Regex para imitar la función js split y extraer el texto

Tengo un texto donde necesito extraer el nombre de la comunidad. El delimitador para dividir es "-"

Por lo tanto Iowa - Cedar Rapids - Meth-Wick Community debe dar como resultado Meth-Wick Community

si la entrada es Iowa - Cedar Rapids - The Gardens of Cedar Rapids resultado debe ser The Gardens of Cedar Rapids

he probado con

 "Iowa - Cedar Rapids - The Gardens of Cedar Rapids".match(new RegExp(/([AZ])\w{3}/gi))
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Prueba este para ver el tamaño:

 console.log("Iowa - Cedar Rapids - The Gardens of Cedar Rapids".replace(/([\w\s]+)\s-\s([\w\s]+)\s-\s([\w\s]+)/i,'$3'));

about 4 years ago · Juan Pablo Isaza Report

0

Puede hacer una búsqueda anticipada negativa para encontrar la última aparición del delimitador como se menciona aquí https://stackoverflow.com/a/8374980/5417843 y luego extraer el nombre de la comunidad.

 input = "Iowa - Cedar Rapids - The Gardens of Cedar Rapids" communityName = input.match(new RegExp('- (?:.(?!- ))+$')) // '- The Gardens of Cedar Rapids' communityName[0].substring(2) // 'The Gardens of Cedar Rapids'
about 4 years ago · Juan Pablo Isaza Report

0

Aquí hay una solución simple, usa menos expresiones regulares tanto como sea posible:

 "Iowa - Cedar Rapids - Meth-Wick Community".split(/ - /g).slice(-1)[0] "Iowa - Cedar Rapids - The Gardens of Cedar Rapids".split(/ - /g).slice(-1)[0]
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!