Skip to content
Advertisement

JavaScript Split String By ONLY Outer Curly Brackets

I’m trying to split a string by curly brackets but ignore nested brackets. E.g given the following:

JavaScript

split into:

JavaScript

Any help would be appreciated!

This is what I have so far:

JavaScript

Advertisement

Answer

You have all the logic in your attempt, you just need to reorder a little and push to the results array.

Here’s a quick working snippet. It can probably be cleaned up or condensed a little, but a way forward at least.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement