|
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
|