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

204
Vistas
Regex solution for matching groups does not work

Imagine a text like in this example:

some unimportant content

some unimportant content [["string1",1,2,5,"string2"]] some unimportant content

some unimportant content

I need a REGEX pattern which will match the parts in [[ ]] and I need to match each part individually separated by commas.

I already tried

const regex = /\[\[(([^,]*),?)*\]\]/g
const found = result.match(regex)

but it doesn't work as expected. It matches only the full string and have no group matches. Also it has a catastrophic backtracking according to regex101.com if the sample text is larger.

Output should be a JS array ["string1", 1, 2, 5, "string2"]

Thank you for your suggestions.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

What about going with a simple pattern like /\[\[(.*)\]\]/g and then you'd just have to split the result (and apparently strip those extra quotation marks):

const result = `some unimportant content

some unimportant content [["string1",1,2,5,"string2"]] some unimportant content

some unimportant content`;

// const found = /\[\[(.*)\]\]/g.exec(result);
const found = /\[\[(.*?)\]\]/g.exec(result); // As suggested by MikeM
const arr_from_found = found[1].replace(/\"/g, '').split(',');

console.log(arr_from_found); // [ 'string1', '1', '2', '5', 'string2' ]
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try replace method.

let cleantext = result.replace("[", "")

then

let more_cleantext = cleantext.replace("]", "")

but if your result variable is array then just

result[0]
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