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