Say I have a referrer that is http://dwz07.foo.net/Player.aspx?All&PID=4321&UID=359010016&STime=921596&SToken=5c93210bdb17ab2c930a1e365b8b05a8e6aca013
What would be the proper regex to include everything before and after foo.net? Like, I want to include every subdomain and everythi开发者_Python百科ng after foo.net/
The best I can come up with:
^([^.]+).foo.net$
But that doesn't work.
Thank you.
Try this:
$string = 'http://dwz07.foo.net/Player.aspx?All&PID=4321&UID=359010016&STime=921596&SToken=5c93210bdb17ab2c930a1e365b8b05a8e6aca013';
$pattern = '/^(.*)(?:\.foo.net.*)/';
$replacement = '$1';
echo preg_replace($pattern, $replacement, $string);
$
anchors the regex to the end of the string, so it would only match a URL which ended with .net
.
Your URL doesn't finish with .net
, it has a /
after: just remove the $
to fix that.
精彩评论