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

292
Visualizações
Is there a RegEx to extract semicolon separated values from a string... possibly containing string with semicolon

I would like to extract values from a string semicolon separated values that could also contains semicolon but not as separator. The RegEx I found on this website (I lost the post) is almost complete because it separates the key and it's value.

Example: my.parameter 10; the.foo "Procedural Map"; pve; server.description "This; is \"my\", my description,.\n"

Current result with [^; "]+|"(?:\\"|[^"])*"/g

[
  'server.seed',
  '10',
  'pve',
  'server.level',
  '"Procedural Map"',
  'server.description',
  '"This; is \\"my\\", server; description,."'
]

Desired result

[
  'my.parameter 10',
  'the.foo "Procedural Map"',
  'pve',
  'server.description "This; is \"my\", server; description,.\n"'
]

Can you help me to improve the RegEx to group the parameter and it's value?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I found a workaround by replacing separator by the ASCII separator (␟) then splitting the result.

const separatorPattern = /; (?=([^"]*"[^"]*")*[^"]*$)/g;

const myRawString = "server.seed 10; server.pve, server.level \"Procedural Map\"; server.description \"This; is \\\"my\\\", server; description,.\"";
const replacedSeparator = myRawString.replace(separatorPattern, "␟");
const parameters = replacedSeparator.split("␟");

console.log(parameters);
/*[
  'server.seed 10',
  'server.pve, server.level "Procedural Map"',
  'server.description "This; is \\"my\\", server; description,."'
]*/
about 4 years ago · Juan Pablo Isaza Relatório

0

You could use a repeating pattern to first match any char except the ; and then optionally match from an opening till closing double quote and match the escaped double quotes in between.

After that optionally repeat the character class [^";\\]* to also match what comes after the closing double quote.

[^;"\\]+(?:"(?:[^"\\]*(?:\\.[^"\\]*)*)"[^";\\]*)*
  • [^;"\\]+ Match 1+ times any char except ; " \
  • (?: Non capture group to repeat as a whole
    • " Match literally
    • (?: Non capture group
      • [^"\\]* Match 0+ times any char except " \
      • (?:\\.[^"\\]*)* Optionally repeat matching \ and any char followed by 0+ times any char except " and \
    • ) Close the non capture group
    • " Match literally
    • [^";\\]* Optionally match any char except " ; \
  • )* Close the outer non capture group and optionally repeat

Regex demo

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