Hi All

This is simple for most of you guys but I have been trying for couple of hours now, and getting no where fast…

I have folder paths like the following,
C:\my folder
c:\perl
f:\cus shared folder.net-03\shated-data
D:\Jan03\acc\emp acc
s:\top lever\lowerdirs
w:\share_A\scin share folder\docs

I need to capture the drive letter and the top-level folders only. I used the code below,
use strict; my $path = shift; $path =~ /^(\w):\\(.+)\\?/; print "Drive : $1, Top Level : $2\n";
However it’s failing, I understand that the error is the \\? bit of the regex. What I am trying to say is, grab the first character and anything in between the first set of 2 back slashes or to the end of the line. It’s easier said than done for me.

Thanks

In reply to filtering folder path using regex. by blackadder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.