public function matchStrings($str, &$uriTemplateVariables)
    {
        $matches = array();
        if (preg_match_all($this->pattern, $str, $matches, PREG_PATTERN_ORDER)) {
            if ($uriTemplateVariables !== null) {
                array_shift($matches);
                if (count($this->variableNames) != count($matches)) {
                    throw new \Exception(
                        "The number of capturing groups in the pattern segment ".$this->pattern
                        . " does not match the number of URI template variables it defines, which can occur if"
                        . " capturing groups are used in a URI template regex. Use non-capturing groups instead."
                    );
                }
                for ($i = 0; $i < count($matches); $i++) {
                    $uriTemplateVariables[$this->variableNames[$i]] = $matches[$i][0];
                }
            }
            return true;
        } else {
            return false;
        }
    }