protected function normalizeRegexPattern($pattern)
    {
        if (false !== @preg_match($pattern, null)) {
            return $pattern;
        }

        $boundedPattern = '~\b' . str_replace('~', '\~', $pattern) . '\b~';

        if (false !== @preg_match($boundedPattern, null)) {
            return $boundedPattern;
        }

        return '~\b' . preg_quote($pattern, '~') . '\b~';
    }