Click here to get back home

Pattern extraction

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Pattern extraction Deepan - M.Sc(SE) - 03MW06 03-10-2008
`--> Re: Pattern extraction Gunnar Hjalmars...03-10-2008
Posted by Deepan - M.Sc(SE) - 03MW06 on March 10, 2008, 4:42 am
Please log in for more thread options
Sorry i didnt explain the previous posy correctly.

I am having a string which can have either one of the below as its
input:

$str="/a/b/c/"; (or) $str = "/a/b/c/d/";


What i need is that regardless of the input it should always be able
to extract "c" from the
above strings. I should not use split. Only by using regular
expressions i should be able to achieve this. Please help me to solve
this.

Thanks,
Deepan


Posted by Gunnar Hjalmarsson on March 10, 2008, 5:57 am
Please log in for more thread options
[ You keep starting new threads for the same problem. Don't do that!! ]

Deepan - M.Sc(SE) - 03MW06 wrote:
> I am having a string which can have either one of the below as its
> input:
>
> $str="/a/b/c/"; (or) $str = "/a/b/c/d/";
>
> What i need is that regardless of the input it should always be able
> to extract "c" from the
> above strings. I should not use split.

Says who?

> Only by using regular expressions i should be able to achieve this.

split() does make use of a regular expression...

Anyway,

if ( $str =~ m#^/[^/]+/[^/]+/([^/]+)# ) {
print "$1\n";
}

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Similar ThreadsPosted
Pattern extraction March 10, 2008, 4:14 am
Pattern Matching and Extraction January 22, 2007, 2:51 pm
Perl pattern extraction March 8, 2008, 7:09 am
Help! Complex Pattern Extraction with Key/Value Pairs and Reg Exp? November 17, 2004, 6:10 pm
Perl pattern matching and extraction March 8, 2008, 8:48 am
hiw do i perform this extraction August 21, 2006, 4:12 am
FTP Link Extraction January 20, 2007, 10:06 am
Statistics Extraction January 23, 2007, 3:25 pm
Help: Content extraction May 9, 2008, 10:30 pm
Whats the way of wildcard HoH extraction? January 17, 2005, 3:36 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap