private function generatePatterns()
    {
        foreach ($this->builders as $uri => $builder) {
            $pattern = '/' . ltrim($uri, '/');

            if (preg_match_all('/{[\w]+}/i', $uri, $matches)) {
                foreach (array_unique($matches[0]) as $match) {
                    $pattern = str_replace($match, '[\w\d\@_~\-\.]+', $pattern);
                }
            }

            $this->patterns['#^' . $pattern . '$#i'] = $uri;
        }

        // Sort patterns to ensure that longer more precisely pattern comes first
        krsort($this->patterns);
    }