CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
delete to end of string (beginner Q)



Jul 5, 2000, 2:33 PM

Post #1 of 3 (8524 views)
delete to end of string (beginner Q) Can't Post

Quick question:

I want to strip the http://www. and .com/* from a string.

In other words, I want "" to become "perlarchive". Is this possible with regular expressions?

User / Moderator

Jul 5, 2000, 4:37 PM

Post #2 of 3 (8524 views)
Re: delete to end of string (beginner Q) [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$url = '';
$url =~ s<^http://www\.(.*?)\.com/.*><$1>;</pre><HR></BLOCKQUOTE>
...does what you asked for.

However, there are many, many URLs that such a substitution would be useless for such as,,, or something really wacky like http:// (and, yes, those all really do work).

Consider yourself warned!


Jul 5, 2000, 8:09 PM

Post #3 of 3 (8524 views)
Re: delete to end of string (beginner Q) [In reply to] Can't Post

Why use s/// when a match works better...
($url) = $url =~ m{^http://www\.(.*?)\.com}
be sure to remember that this is not the same as
$url = $url =~ m{^http://www\.(.*?)\.com}
..that one calls the match in scalar context (a true/false) instead of in list context (returns a list of the $DIGITs)

all the caveats kanji mentioned


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives