protected static function compilePatternAsRegex($pattern, $rules=[], $extract_params=true){

      return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#',$extract_params
        // Extract named parameters
        ? function($g) use (&$rules){
            return '(?<' . $g[1] . '>' . (isset($rules[$g[1]])?$rules[$g[1]]:'[^/]+') .')';
          }
        // Optimized for matching
        : function($g) use (&$rules){
            return isset($rules[$g[1]]) ? $rules[$g[1]] : '[^/]+';
          },
      str_replace(['.',')','*'],['\.',')?','.+'],$pattern)).'$#';
    }