0

I'm trying to split string

x@x,a,b,c,d(some(other,arg2),p)@yyy into array

['x@x','a','b','c','d(some(other,arg2),p)@yyy'].

The problem i faced is that i cannot split just comma /\,/g since members that contains already commas would split also. Any ideas?

Tiit Remmel
  • 230
  • 1
  • 5
  • 16
  • 1
    Regex only solution: https://regex101.com/r/VaLYJb/1 – SamWhan Oct 05 '17 at 07:58
  • @Wiktor your provided answer link doesn't work for this case (copied from the comments) - 'cats,(my-foo)-bar,baz' which should return three elements, cats, (my-foo)-bar, and baz. But instead it returns cats(my-foo), -bar, and baz. See my solution instead. Although that is an accepted answer yet that doesn't mean it should be accepted for all – Mustofa Rizwan Oct 05 '17 at 08:02
  • @RizwanM.Tuman There are others, too. There are lots of such answers. I will add more. – Wiktor Stribiżew Oct 05 '17 at 08:06
  • See [this demo](https://jsfiddle.net/acvcbsLk/). Adapted from the [Regex split string by spaces taking into account nested brackets](https://stackoverflow.com/questions/44405230/regex-split-string-by-spaces-taking-into-account-nested-brackets) by mere replacing a space with `,`. – Wiktor Stribiżew Oct 05 '17 at 08:12

0 Answers0