我已经尝试使用以下正则表达式,但它没有按预期工作(xampp php)
$slug = "test123/abc_xyz-001" //this is valid
$reg = '/^[a-zA-Z0-9_-/]+$/';
if (preg_match($reg, $slug)) { // the slug shoul only contain the combination of alpha numeric and _ - /
//It is a valid path
}
else{
//not valid
}
有效案例
ABC
123
abc12d3
abc_123s
ABC-XYZ
test123 / abc_xyz-001