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

57
Visualizações
Regex to also handle escaped delimiters?

Say I have an input text cells of data delimited by colons, and I want to split that into matches based on runs of one or more colons, ignoring any initial leading colons.

Thus,

  • data_A:data_B:data_C: is split into data_A:, data_B:, data_C:
  • :data_A:data_B:data_C: is split into data_A:, data_B:, data_C:
  • ::data_A:data_B:::data_C: is split into data_A:, data_B:::, data_C:

A regex of /[^:].*?(?::+|$)/g appears to work. https://regex101.com/r/JuMZ65/1

However, I need to make this work where the colon character itself might be in a data cell, in which case it would be written as \:.

The above regex fails:

  • data_A::data_\:B: is split into data_A::, data_\:, B:
  • but the split wanted is data_A::, data_\:B

Additionally, the backslash itself could be escaped, like this

  • data_A::data_\:B:data_\\:C should get split into data_A::, data_\:B, data_\\:, C

What regex will work, handling \: and \\:?


(My thinking process is not much more sophisticated than just throwing mud at the wall, so I'll spare you the mess of dozens of slight variations, half of which simply die on the table.)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use

/(?:[^:\\]|\\.)+(?::+|$)/g
// If the match can have no trailing colons not at the end of string:
/(?:[^:\\]|\\.)+:*/g

See the regex demo. Details:

  • (?:[^:\\]|\\.)+ - one or more occurrences of
    • [^:\\] - any char other than : and \
    • | - or
    • \\. - an escaped char other than a line break char
  • (?::+|$) - either one or more colons or end of string.
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