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

55
Vistas
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 Respuestas
Responde la pregunta

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