I'm trying to match URLs with wildcards in them to actual URLs.
For example:
http://*.example.com/product/*/shop/
Needs to match
http://a.example.com/product/table/shop/
http://b.example.com/product/shoe
I have tried below regex so far and it is not working in all cases:
/([a-zA-Z0-9\-_*]+\.)?([a-zA-Z0-9\-_]+\.[a-zA-Z\.]{1,}[^\" ]+)/i
/([https?:\/\/])(\*.)?([^\" ]+)(\*.)?/i
Can someone please help me with this?
try this:
$re = "/(https?:\\/\\/)([a-zA-Z0-9]+)\\.(example.com\\/product\\/)([a-zA-Z0-9]+)(\\/shop)\\/?/";
$str = "http://a.example.com/product/table/shop/
http://b.example.com/product/shoe/";
$subst = "";
$result = preg_replace($re, $subst, $str);