Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regexp to find first occurence in a string

Status
Not open for further replies.

fyyap

Programmer
Oct 29, 2001
9
SG
Hi

I would like to find a first occurence from last in a string.

For example, these are my entries:-

/IVR/directory1/vfs1/talkfiles/103/filename1
/IVR/directory2/vfs2/talkfiles/106/filename2.txt
/IVR/directory3/test/talkfiles/106/filename3.doc

Is there any regexp can help me to find my file names?

Thanks
 
use reverse
find the "/"
and reverse again
Code:
$fname="/IVR/directory1/vfs1/talkfiles/103/filename1";
$rfname=reverse $fname;
(@info)=split (/\//, $fname);
$filename=reverse $info[0];
[code]

HTH
--Paul
 
Code:
$fullpath = "/some/dir/with/a/file";

# With a regexp
$fullpath =~ m{.*/(.*)};
$filename = $1;

#with split
@dirs = split(/\//, $fullpath);
$filename = $dirs[$#dirs];

--------------------

Denis
 
You do not want to parse this yourself.

Use File::Basename

You feed it an OS type and the path and it will get you all the info you require.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top