We help IT Professionals succeed at work.

how to capture a directory structure and the file name in a string in Perl?

Tolgar
Tolgar asked
on
Hi,
I have a string as the following:

See 20120816_1406_Report.html for details in //dir1/dir2/dir3/dir4/dir5/dir6 directory.

Open in new window


I would like to create another string from this string as the below:

//dir1/dir2/dir3/dir4/dir5/dir6/20120816_1406_Report.html

Open in new window


In general I need to catch the directory structure and the html file in this string basically.

Thanks,
Comment
Watch Question

CERTIFIED EXPERT
Commented:
my $str = 'See 20120816_1406_Report.html for details in //dir1/dir2/dir3/dir4/dir5/dir6 directory.';

my ($file, $path) = $str =~ m{(\w+\.html)[^/]+(//\S+)};

my $fullname = "$path/$file";

print $fullname;

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.