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

161
Visualizações
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 Respostas
Responde à pergunta

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