I managed the problem by myself. I had to add a ^ before the expression and +$ after it. So that the function looks like this:
private function routes()
{
// Loop through the routes
foreach($this->routes as $route)
{
// Set the pattern to the matching url
$pattern = $route['url'];
// Check if the pattern contains :id
if (strpos($route['url'], ':id'))
{
// Build the pattern
$pattern = str_replace(':id','([0-9]+)', $pattern);
}
// Check if the requested url matches the pattern
if (preg_match_all('~^' . $pattern . '+$~', $this->_url, $matches))
{
// If so, set the url_parts var
$this->url_parts = explode('/', $route['target']);
// Remove the first index of the matches array
array_shift($matches);
// Set the params var
$this->_params = $matches;
}
}
}