Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda