Pattern extraction

  • Thread starter Deepan - M.Sc(SE) - 03MW06
  • Start date
D

Deepan - M.Sc(SE) - 03MW06

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
 
G

Gunnar Hjalmarsson

[ You keep starting new threads for the same problem. Don't do that!! ]
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";
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top