我正在尝试将带有通配符的URL与实际URL进行匹配。
例如:
http://*.example.com/product/*/shop/
需要匹配
http://a.example.com/product/table/shop/
http://b.example.com/product/shoe
到目前为止,我已经尝试过下面的regex,但它并不是在所有情况下都有效:
/([a-zA-Z0-9-_*]+.)?([a-zA-Z0-9-_]+.[a-zA-Z.]{1,}[^" ]+)/i
/([https?://])(*.)?([^" ]+)(*.)?/i
有人能帮我做这个吗?
试试这个:
$re = "/(https?:\/\/)([a-zA-Z0-9]+)\.(example.com\/product\/)([a-zA-Z0-9]+)(\/shop)\/?/";
$str = "http://a.example.com/product/table/shop/nhttp://b.example.com/product/shoe/";
$subst = "";
$result = preg_replace($re, $subst, $str);
在这里进行实时演示