'Is it possible to match a nested pair with regex?

Im attempting to parse some BBCode with regex, but the nested structures are giving me a headache

What I'm trying to parse is the following:

[COLOR="Red"]Red [COLOR="Green"]Green[/COLOR][/COLOR]

I've come up with the following pattern, which I need to deal with the quotation marks around the color attribute, but it only matches the first leading COLOR and the first closing COLOR. Its not matching in a proper nested arrangement

\[COLOR=(\"?)(.*?)(\"?)]([\s\S]*?)\[\/COLOR\]\

Its being done in dart, as follows, but really I believe the problem might be with my regex pattern rather then the dart implementation

  text = text.replaceAllMapped(RegExp(r'\[COLOR=(\"?)(.*?)(\"?)]([\s\S]*?)\[\/COLOR\]', caseSensitive: false, multiLine: true), (match) {
    return '<font style="color: ${match.group(2)}">${match.group(4)}</font>';
  });


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source