This seems to be a frequent kind of question here on StackOverflow, but I couldn't get it working properly. Apologies for any inconvenience.
I need to split a string for every comma found outside of a group delimited by pairs of dollar signs. I'm using Javascript.
Expected behavior: "$g=9,8m/s$, p,q, $m=19,0$, banana"
Should return ["$g=9,8m/s$", "p", "q", "$m=19,0$", "banana"]
Ideally, dollar signs prefixed by \ should be ignored as follows:
"$$g=9,8m/s$$, p,q, $price=\$19,0$, banana"
Returns ["$$g=9,8m/s$$", "p", "q", "$price=\$19,0$", "banana"]
But for now I'm happy without this feature.
My best attempt was (\$[^\$]*\$)|[^,]+
Which matches just the first group, returning: ["$g=9,8m/s$", "p", "q", "$m=19", "0$, "banana"]
What am I getting wrong here? Appreciate your help!