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
Split Down Unescaped Character in Javascript

I have a period and backslash escaped string. I would like to split the string using any unescaped periods, but am struggling to come up with a pattern to do so.

const escaped = "two slashes: \\\\.one period: \..line and a dot: \\\.";

// ["two slashes: \\", "one period: .", "line and a dot: \."]
console.log(escaped.split(/* ? */))

This (?<!\\)(?:(\\\\)*)[*] is close, but split() includes capturing groups in the ouput array, which is not what I would like. The solution should be match-only, like here:

(?<!\\)(?:\\\\)*\K\.
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The positive lookbehind solution will work with any JavaScript environment compatible with ECMAScript 2018+ standard:

/(?<=(?<!\\)(?:\\\\)*)\./

See this regex demo.

enter image description here

The regex matches any . char that is immediately preceded with any amount of an even amount of backslashes (i.e. even if there are no backslashes before . at all).

With older JavaScript environment, you will need a workaround like text.match(/(?:\\[^]|[^\\.])+/g). See this regex demo. This matches any one or more sequences of a a \ and any single char or any single letter other than a backslash and a dot.

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