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

180
Visualizações
How to split by nonescaped dot and by ignoring double blackslash?

I need to split data by dot. And I have escaped dot(.), that I should ignore. Also I should ignore escaped backslash too (\). For example,

data1\\.d\\\\\.ata2\\\\.da\.ta3.data4

This string should be splitted to for substrings like as

data1\\
d\\\\\.ata2\\\\
da\.ta3
data4

I cannot to create regex for that. Do you know, it is possible? I tried to use following:

(?<!\\((\\\\){2,}))\\. - not working

I can create following regex if escaped slash defined only one time:

"((?<!\\\\)\\.)|((?=([^\\\\]*((\\\\\\\\)+[^\\\\]*)))\\.)";

For example data1\\.d\.ata2.da\.ta3.data4 splitted correctly:

data1\\
d\.ata2
da\.ta3
data4 

But I cannot detect backslash definition even number times. Can you help me, please? Thank you!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You may extract these strings using

(?s)(?:[^\\.]|\\.)+

See the regex demo. Details:

  • (?s) - enable the Pattern.DOTALL flag so that . could match across lines
  • (?:[^\\.]|\\.)+ - one or more occurrences of any char other than \ and ., or a \ followed with any char.

See a Java demo:

String line = "data1\\\\.d\\.ata2.da\\.ta3.data4";
Pattern p = Pattern.compile("(?s)(?:[^\\\\.]|\\\\.)+");
Matcher m = p.matcher(line);
List<String> res = new ArrayList<>();
while(m.find()) {
    res.add(m.group());
}
System.out.println(res);
// => [data1\\, d\.ata2, da\.ta3, data4]
over 4 years ago · Santiago Trujillo Relatório

0

You may use this regex to get your matches:

(?=[^.])[^.\\]*(?:\\.[^.\\]*)*(?=\.|$)

RegEx Demo

RegEx Demo:

  • (?=[^.]): Make sure there is non-dot character ahead
  • [^.\\]*: Match 0+ of any character that is not a . not a \
  • (?:\\.[^.\\]*)*: A non-capture group that matches an backslash followed by an escaped character and that should be followed by 0 or more of any character that is not a . not a \. Match 0 or more of this group
  • (?=\.|$): Make sure we have a dot or end of line ahead
over 4 years ago · Santiago Trujillo 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