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

58
Views
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 answers
Answer question

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