public function extract() {
        foreach ($this->log as $line) {
            foreach ($this->messageGroupsJoined as $header => $keywords) {
                $pattern = $this->getPattern($keywords);

                if (preg_match($pattern, $line)) {
                    $this->appendToGroup($header, $line, $pattern);
                }
            }
        }

        // Remove empty groups
        foreach (array_keys($this->messageGroups) as $groupKey) {
            if (true === empty($this->groups[$groupKey])) {
                unset($this->messageGroups[$groupKey]);
            }
        }

        // The array_merge sorts $messageGroups basing on $groups
        return array_merge($this->messageGroups, $this->groups);
    }