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

163
Vistas
Split a string by comma in excluding braces

I am very much new to regex and I have a requirement to split a string by comma and generate a array out of it. Any pointer will be really helpful.

In my result array should have 3 item and all nested comma inside {} and () need to be ignored split should be done only on outer comma. Refer the output image

I have tried below regex in javascript but it is not solving problem completly

,(?!\[^{\[('\]\*\[}\])'\])/g

Actual string

let mystr =`attrs :{id:'hello'},ojComponent: {component:'Button', display: 'icons', chroming: 'half', icons: {start:'cartWedgitIcon', end: null}, label: $module.cartBtnLabel}, visible:('true',condition)`;
let arrayofItem = mystr.split(\<\<Regex\>\>);

**Expected output **

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

0

I suggest you trying to get firstly pure words out of context by implementing regular expression. Then, because in JSON every word including keys and values demand to be wrapped by single or double quotes, you may add it after getting each word inside an array function. You should use array methods to work on each word. Code sample I may suggest to use is below.

const regX = /[a-zA-Z]+/; let matched = yourString.match(regX);

P.S. Don't forget to retain true and false words out of context as they aren't wrapped inside quotes.

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