<?php function getRegexUri(string $uri): string { return '#^' . \preg_replace_callback( '/\/\{(\??)([a-zA-Z_][a-zA-Z0-9_]*)(?::([^}]+)|<([^>]+)>)?}/', function (array $matches): string { $regex = $matches[3] ?? null; $type = $matches[4] ?? null; if ($regex === '') { $regex = null; } $pattern = $regex ?? $this->patterns->get($type ?? '')->regex ?? '[^/]+'; $segment = '(?<' . $matches[2] . '>' . $pattern . ')'; return $matches[1] === '?' ? '(?:/' . $segment . ')?' : '/' . $segment; }, $uri, ) . '$#'; } $v = '/test-http-{code:\d+}/'; var_dump(getRegexUri($v));
You have javascript disabled. You will not be able to edit any code.