Perl pattern matching and extraction

Discussion in 'Perl Misc' started by Deepan - M.Sc(SE) - 03MW06, Mar 8, 2008.

  1. 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
     
    Deepan - M.Sc(SE) - 03MW06, Mar 8, 2008
    #1
    1. Advertising

  2. [ You shouldn't have started a new thread for the same problem! ]

    Deepan - M.Sc(SE) - 03MW06 wrote:
    > 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";
    }

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Mar 8, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manasa
    Replies:
    2
    Views:
    787
    Mothra
    May 19, 2004
  2. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    264
    Marc Bissonnette
    Jan 13, 2004
  3. doni

    Pattern Matching and Extraction

    doni, Jan 22, 2007, in forum: Perl Misc
    Replies:
    10
    Views:
    190
    John Bokma
    Jan 23, 2007
  4. Bobby Chamness
    Replies:
    2
    Views:
    268
    Xicheng Jia
    May 3, 2007
  5. Deepan - M.Sc(SE) - 03MW06

    Perl pattern extraction

    Deepan - M.Sc(SE) - 03MW06, Mar 8, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    111
    Tad J McClellan
    Mar 9, 2008
Loading...

Share This Page