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

297
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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