I would normally not post a suggestion being still fairly new to perl, but I
just wrote a snippet that addresses this situation.  As you can tell I do
better at splits than regexs:

$_ = "http://www.website.net/action.lasso?-database=Links_Engine";;

my @split = split (/\//);
$finish = $split[0]."//".$split[2];
print $finish;

-----Original Message-----
From: Curtis Poe [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 14, 2001 1:32 PM
To: Luinrandir Hernson; [EMAIL PROTECTED]
Subject: Re: string question


--- Luinrandir Hernson <[EMAIL PROTECTED]> wrote:
> I am receiveing these long website addresses and I want to shorten them
after a certain symbol
> like a question mark or a word like "/action". Is there an easy way to do
that?
> 
> EX:
> http://www.website.net/action.lasso?-database=Links_Engine
> 
> TO:
> http://www.website.net/action.lasso
> OR EVEN
> http://www.website.net

Unless I am mistaken, you cannot have a question mark in the URL before the
beginning of the query
string.  Thus, you can do this:

$url =~ s/\?.*//;

If you just want the the protocol along with the host/domain, you could do
this:

$url =~ s!^([a-zA-Z]+://)?([^/]+).*!$1$2!;

The first one is fairly simple.  The second one breaks down to:

$url =~ s!^             # match at start of string
            (           # capture to $1
              [a-zA-Z]+ #   1 or more letters
              ://       #   ://
            )?          # end optional capture
            (           # capture to $2
              [^/]+     #   1 or more non-forward slashes
            )           # end capture
            .*          # slurp rest of string
         !$1$2!xs;

Of course, if you don't have the protocol on the URL (the http part), then
you won't have it in
the resulting URL.

Cheers,
Curtis Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply via email to