protected function getConfiguredRule($configuration, RuleInterface $rule)
    {
        $configurationNormalized = str_replace(array("\r\n", "\r"), "\n", (string) $configuration);
        $rxSearch = '/';
        // First of all we have either the start of the file or a line ending
        $rxSearch .= '(^|\n)';
        $commentsBefore = $rule->getCommentsBefore();
        if ($commentsBefore !== '') {
            // Then we may have the opening comment line
            $rxSearch .= '(\s*'.preg_quote($commentsBefore, '/').'\s*\n+)?';
        }
        // Then we have the rule itself
        $rxSearch .= '\s*'.preg_replace("/\n\s*/", "\\s*\\n\\s*", preg_quote($rule->getCode(), '/')).'\s*';
        $commentsAfter = $rule->getCommentsAfter();
        if ($commentsAfter !== '') {
            // Then we may have the closing comment line
            $rxSearch .= '(\n\s*'.preg_quote($commentsAfter, '/').'\s*)?';
        }
        // Finally we have the end of the file or a line ending
        $rxSearch .= '(\n|$)';
        $rxSearch .= '/';

        return preg_match($rxSearch, $configurationNormalized, $match) ? $match[0] : '';
    }