I have an expression which I need to split and store in an array:
aaa=\"bbb{ccc}ffffd\" { aa=\"bb,cc\" { a=\"b\", c=\"d\" } }, aaa=\"bbb{}\" { aa=\"b}b\" }, aa
Although Recursive Regular Expressions can usually be used to capture "balanced braces" {}
, they won't work for you, because you ALSO have the requirement to match "balanced quotes" "
.
This would be a very tricky task for a Perl Regular Expression, and I'm fairly certain it's not possible. (In contrast, it could probably be done with Microsoft's "balancing groups" Regex feature).
I would suggest creating your own parser. As you process each character, you count each "
and {}
, and only split on ,
if they are "balanced".