Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Pattern extraction

Reply
Thread Tools

Pattern extraction

 
 
Deepan - M.Sc(SE) - 03MW06
Guest
Posts: n/a
 
      03-10-2008
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

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-10-2008
[ 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl pattern extraction Deepan - M.Sc(SE) - 03MW06 Perl Misc 4 03-09-2008 01:56 AM
Pattern Matching and Extraction doni Perl Misc 10 01-23-2007 11:37 PM
Extraction of attribute values from pattern matches Peekachu Java 1 07-10-2006 07:59 PM
Help! Complex Pattern Extraction with Key/Value Pairs and Reg Exp? aekalman Perl Misc 6 11-22-2004 10:59 PM
Pattern Search and Extraction of Floating Point number to csv file Ram Laxman Perl 1 07-15-2004 04:16 PM



Advertisments