I believe if you move the dash ("-") to the end of the class definition
(i.e.  /\\([\w\.\s_-]+)$/g;), Anthony's regex will probably work without
giving a warning (I have not tested this though).

Chad Uretsky
Lead Network and Security Engineer, IT | NetIQ Corporation
Direct 713.418.5200 | Fax 713.548.1771 | www.netiq.com
1233 West Loop South | Suite 1800 | Houston, TX, 77345




-----Original Message-----
From: Dirk Bremer [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 21, 2005 4:37 PM
To: [EMAIL PROTECTED]; Chad I. Uretsky
Cc: [EMAIL PROTECTED];
[email protected]
Subject: RE: Filename pull


Anthony,
 
I tried your regex example out of curiosity:
 
my $str = 'C:\Program
Files\Oracle\Inventory\Components21\oracle.swd.jre\1.1.8.16.0\resources\
CompID.properties';
$str =~ /\\([\w\._-\s]+)$/g;
print(">$1<\n"); 

While it does produce the correct result in this instance, it also produces
a warning:
 
c:\temp>regex
False [] range "_-\s" before HERE mark in regex m/\\([\w\._-\s << HERE ]+)$/
at C:\Perl\Scripts\regex.pl line 7.
>CompID.properties<



________________________________

        From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
        Sent: Thursday, April 21, 2005 15:54
        To: Chad I. Uretsky
        Cc: [EMAIL PROTECTED];
'[email protected]'
        Subject: RE: Filename pull
        
        

        To add to Chad's last email, the following will cater for spaces and
special (allowed) characters in the file name 
        
        $s1 = "c:\\temp\\bola\\temilola\\abolan-lef o_o.pl"; 
          
        $s1 =~/\\([\w\._-\s]+)$/g; 
        
        print $1; 
        
        Tony B. Okusanya
        Distributed Technology Group
        
        
        "Live Life By Design And Not From Crisis to Crisis" 
        
        
        
        "Chad I. Uretsky" <[EMAIL PROTECTED]> 
        Sent by: [EMAIL PROTECTED] 

        04/21/2005 03:03 PM 

                
                To
                "'[email protected]'"
<[email protected]> 
                cc
                
                Subject
                RE: Filename pull

                




        try: 
          
        $s1 = "c:\\temp\\foo.pl"; 
          
        $barename = ($s1 =~ /\\(\w+\.\w+)$/)[0]; 
          
          
          
        -----Original Message-----
        From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
        Sent: Thursday, April 21, 2005 1:59 PM
        To: [email protected]
        Subject: Filename pull
        
        
        Hey, wizards. 
        
        I've got this problem: pulling the bare filename off of a fully
pathed string, using split. The tricky part is getting the last element in
the array when I don't know how many members are in it. Example: 
        
        $s1 = "c:\\temp\\foo.pl"; 
        $barename = (split( /\\/, $s1)[2];  # $barename gets "foo.pl" 
        
        Now obviously this works as far as it goes, but what I should put
inside those square brackets to make sure I always grab the filename, even
in varied cases like these 
        
        $s2 = "c:\\windows\\fee\\fie\\fo\\fum\\foo.pl"; 
        $s3 = "c:\\base_foo.pl"; 
        
        is the question.  If it was a regular array, I know I could get it
using $#, like this: 
        
        @x = ("C:", "windows", "fee", "fum", "foo.pl"); 
        $barename = $x[$#x]; 
        
        Do I have to go to an intermediate step, assigning the output of
split() to an array like @x? Or does someone have handy a regexp to do the
dirty work? 
        
        Thanks! 
        
        Deane_______________________________________________
        ActivePerl mailing list
        [email protected]
        To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs 
        

        
------------------------------------------------------------------------
------
        Electronic Privacy Notice. This e-mail, and any attachments,
contains information that is, or may be, covered by electronic
communications privacy laws, and is also confidential and proprietary in
nature. If you are not the intended recipient, please be advised that you
are legally prohibited from retaining, using, copying, distributing, or
otherwise disclosing this information in any manner. Instead, please reply
to the sender that you have received this communication in error, and then
immediately delete it. Thank you in advance for your cooperation.
        
========================================================================
======
        
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to