Perl pattern matching and extraction

  • Thread starter Deepan - M.Sc(SE) - 03MW06
  • Start date
D

Deepan - M.Sc(SE) - 03MW06

Hi,
I would like to thank everyone for their help to my previous
post. Actually i didn't explained my need completely. Here's it

my $url = "/pages-cell.net/deepan/sony/";

if($url =~ m/\/(.*)\//g)
{
my @result = $1;
return @result;
}

What i need is that i should be able to extract "sony" from it. In the
sense i should be able to extract whatever that is available in the
last between "/" and "/". Please help me to solve this.

Thanks,
Deepan
 
G

Gunnar Hjalmarsson

[ You shouldn't have started a new thread for the same problem! ]
Hi,
I would like to thank everyone for their help to my previous
post. Actually i didn't explained my need completely. Here's it

my $url = "/pages-cell.net/deepan/sony/";

if($url =~ m/\/(.*)\//g)
{
my @result = $1;
return @result;
}

What i need is that i should be able to extract "sony" from it. In the
sense i should be able to extract whatever that is available in the
last between "/" and "/". Please help me to solve this.

This can still be easiest solved with split().

( split /\//, $url )[-1]

Otherwise you can do:

if ( $url =~ m#.*/(.+)/# ) {
print "$1\n";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top