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
Posted by Deepan - M.Sc(SE) - 03MW06 on March 10, 2008, 4:14 am
Please log in for more thread options
I am having a string like below:

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

What i need is that i 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 Frank Seitz on March 10, 2008, 4:26 am
Please log in for more thread options
Deepan - M.Sc(SE) - 03MW06 wrote:
> I am having a string like below:
>
> $str="/a/b/c/"; (or) $str = "/a/b/c/d/";
>
> What i need is that i 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.

($val) = $str =~ m|/([^/]+)/$|;

$ perldoc perlrequick
$ perldoc perlretut
$ perldoc perlre

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Posted by Tad J McClellan on March 10, 2008, 6:46 am
Please log in for more thread options
> I am having a string like below:
>
> $str="/a/b/c/"; (or) $str = "/a/b/c/d/";
>
> What i need is that i should always be able to extract "c" from the
> above strings. I should not use split.


Why not?


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Posted by Jürgen Exner on March 10, 2008, 7:51 am
Please log in for more thread options
>I am having a string like below:
>
> $str="/a/b/c/"; (or) $str = "/a/b/c/d/";
>
>What i need is that i should always be able to extract "c" from the
>above strings. I should not use split.

Why? It is the most natural tool for this task:

        my $res = (split('/', $str))[3];

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

1: the first argument of split() is a regular expressions
2: As stated the task is impossible because you need some other function
beside the RE to apply the RE, e.g. a s/// or m//

jue

Posted by Charlton Wilbur on March 10, 2008, 9:55 am
Please log in for more thread options

D> I am having a string like below: $str="/a/b/c/"; (or) $str =
D> "/a/b/c/d/";

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

Split is the best way to solve this in Perl.

If this restriction is because that's what your teacher said, go ask
your teacher. He or she is being paid to teach you; we are not.

If this restriction is because you're using some language other than
Perl, which doesn't have a split function, ask in a forum appropriate
for that language.

Charlton


--
Charlton Wilbur
cwilbur@chromatico.net

Similar ThreadsPosted
Pattern extraction March 10, 2008, 4:42 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