public function getCurrentFormatting($string)
    {
        $stack = [];
        foreach ($this->getStyleStack($string) as $style) {
            if (preg_match(static::REGEX_FIRST_KEY, $style, $matches)) {
                $key = $matches[0];

                // if this is a valid setting style, add it to the stack
                if (array_key_exists($key, $this->formats)) {
                    $stack[] = ['key' => $key, 'style' => $style];
                } else {
                    // otherwise remove all elements that this turns off from the current stack
                    if ($key === static::STYLE_RESET) {
                        $stack = [];
                    } else {
                        $stack = array_filter($stack, function ($item) use ($key) {
                            return !in_array($key, $this->formats[$item['key']]);
                        });
                    }
                }
            }
        }

        if (count($stack) === 0) {
            return '';
        }

        $items = array_map(function ($item) {
            return $item['style'];
        }, $stack);
        return sprintf(static::ESCAPE . '[%sm', implode(';', $items));
    }