Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Strip part of url

by silent11 (Vicar)
on Feb 11, 2011 at 19:41 UTC ( #887667=note: print w/ replies, xml ) Need Help??


in reply to Strip part of url

my $url = "http://google.com/folder/1234.html"; my @parts = split /\//, $url; (my $numbers )= $parts[-1] =~ m/(\d+)/; print $numbers; # 1234


Comment on Re: Strip part of url
Download Code
Re^2: Strip part of url
by htmanning (Scribe) on Feb 11, 2011 at 20:00 UTC
    Perfect. Thanks so much!
Re^2: Strip part of url
by roboticus (Canon) on Feb 11, 2011 at 20:53 UTC

    silent11:

    That's a bit wordy, and you're using multiple regular expressions. If you make your regular expression a little more complex, you can do it like this:

    my $url = "http://google.com/folder/1234.html"; my $numbers = $url; $numbers =~ s#^.*(\d+)[^/]*$#$1#; print $numbers;

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://887667]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-09-16 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (9 votes), past polls