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

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

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