public static function getGroupedFields($formatString, FieldOverrides $fieldOverrides = null)
    {
        $groupedFields = [];
        $hiddenFields = $fieldOverrides ? $fieldOverrides->getHiddenFields() : [];
        $expression = '/\%(' . implode('|', AddressField::getAll()) . ')/';
        $formatLines = explode("\n", $formatString);
        foreach ($formatLines as $index => $formatLine) {
            preg_match_all($expression, $formatLine, $foundTokens);
            foreach ($foundTokens[0] as $token) {
                $field = substr($token, 1);
                if (!in_array($field, $hiddenFields)) {
                    $groupedFields[$index][] = substr($token, 1);
                }
            }
        }
        // The indexes won't be sequential if there were any rows
        // without tokens, so reset them.
        $groupedFields = array_values($groupedFields);

        return $groupedFields;
    }