3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! $wildcard = '*'; $urlParts = array( 'path' => 'example.com/sub/path/wildcard/*' ); $patternParts = explode($wildcard, $urlParts['path']); foreach ($patternParts as &$pPart) { $pPart = preg_quote($pPart, '/'); } unset($pPart); //Случай, когда * находится в конце строки - возможны любые вложенные пути if ($patternParts[count($patternParts)] = '') { array_pop($patternParts); if (count($patternParts) > 1) { $pattern = implode('\w+', $patternParts); } else { $pattern = $patternParts[0]; } $pattern.= '[\w\/]+'; } else { $pattern = implode('\w+', $patternParts); } $pattern = '/^' . $pattern . '$/im'; var_dump($pattern);

preferences:
42.4 ms | 402 KiB | 5 Q