- preg_match: documentation ( source)
<?PHP
$paths = [
'.*/cars$',
'^cars/.*/',
'/trucks$',
'.*/trucks$'
];
$url = 'some-site.com/cars';
foreach($paths AS $v) {
if (preg_match('~'.$v.'~', $url, $out)) {
echo $v.' matched this part of $url: '.$out[0]; break;
}
}
?>