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

200
Vistas
Regex to mimic the js split function and extract the text

I have a text where I need to extract the community name The delimiter for spliting is " - "

Hence Iowa - Cedar Rapids - Meth-Wick Community must give result as Meth-Wick Community

if input is Iowa - Cedar Rapids - The Gardens of Cedar Rapids result must be The Gardens of Cedar Rapids

I have tried with

"Iowa - Cedar Rapids - The Gardens of Cedar Rapids".match(new RegExp(/([A-Z])\w{3}/gi))
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Try this one out for size:

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 Denunciar

0

You can do a negative lookahead to find the last occurrence of the delimiter as mentioned here https://stackoverflow.com/a/8374980/5417843 and then extract the community name from it.

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 Denunciar

0

Here's a simple solution, used less regex as much as possible:

"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 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