
japhy
Enthusiast
/ Moderator
Nov 27, 2000, 2:50 PM
Post #2 of 2
(901 views)
|
Don't use a regex for this. Use the rindex() function -- it's better suited for the task: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> $path = 'c:\users\jeffp\file.txt'; # eww, backslashes are bad $last_slash = rindex($path, '\\'); $filename = substr($path, $last_slash + 1); print $filename; # file.txt </pre><HR></BLOCKQUOTE> If you really want to use regexes, I'd suggest: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> ($filename) = $path =~ /([^\\]*)$/; </pre><HR></BLOCKQUOTE> That matches the last set of non-\ characters in $path, and stores them in $filename. ------------------ Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher
|