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

Posted on 2012-08-16
Last Modified: 2012-08-16
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:


Open in new window

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

Question by:Tolgar
    1 Comment
    LVL 31

    Accepted Solution

    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


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now