Given a string such as
1, 'str,ing', [1, 2, [3, 4, 5, 'str,ing']], 'st[rin,g]['
I want to split it based on commas, but excluding commas inside inner strings or square brackets. So I would like the output to be a list of
1
'str,ing'
[1, 2, [3, 4, 5, 'str,ing']]
st[rin,g]['
Closest I've gotten is with ,(?=(?:[^'"[\]]*['"[\]][^'"[\]]*['"[\]])*[^'"[\]]*$)
, but this doesn't realize that ]
doesn't close a '
and such.