in reply to Help with a small regex

Thanks for the help you two. I forgot to mention that "testdir" can and will change (the matches definitely won't contain "testdir"). Your solutions work, but they also match "scp". I just added
next if /scp/;
to the loop along with if !/:/ to fix it.

Replies are listed 'Best First'.
Re^2: Help with a small regex
by AnomalousMonk (Archbishop) on Feb 06, 2015 at 22:11 UTC

    I don't see why hippo's second second suggestion above (the OTOH one) would not cover all your cases:

    c:\@Work\Perl\monks>perl -wMstrict -le "for my $path ( 'scp', 'sss40s1u01:/home/example/test.txt', '/home/example/testdir' +, @ARGV, ) { print qq{'$path' matches} if $path =~ /^\//; } " "/any" "/other/examples" '/home/example/testdir' matches '/any' matches '/other/examples' matches
    (BTW: My own preference for the regex expression would be  m{ \A / }xms rather than  /^\//)


    Give a man a fish:  <%-(-(-(-<