Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Filter a url

2 views
Skip to first unread message

Eelco Alosery

unread,
Oct 31, 2004, 7:48:10 AM10/31/04
to macperl...@perl.org
Hello,

I want to filter a url from $ENV{'HTTP_REFERER'}
If the url is http://www.testdomein.nl/test.html
I only want a result testdomein.nl

I have been testing whit this script
$url =~ s/.*?\.(.+?)\/.*?/$1/is;

It delets the first part of the url corect, but after .nl it deletes
the slash and not the remaining tekst.
The result is testdomein.nltest.html

What is it i do wrong.

Thanks,
Eelco Alosery

Ronald J Kimball

unread,
Oct 31, 2004, 7:46:01 PM10/31/04
to Eelco Alosery, macperl...@perl.org

.*? matches as few characters as possible. Since it's at the end of your
regex, it never has to match anything.

This will work better:

$url =~ s,.*?\.(.+?)/.*,$1,is;

You may have to tweak it for URLs such as this:

http://testdomein.nl/test.html

Ronald

John Delacour

unread,
Nov 5, 2004, 12:57:44 PM11/5/04
to Eelco Alosery, macperl...@perl.org


Try something like this:

$_ ="http://www.testdomain.nl/test.html";

s~ [^\.]+. ([^/]+) /.+ ~$1~x;

print "$_$/";


JD


0 new messages