Assuming that path doesn't have "\" in it,
$str = '\\Server\Path';
$str =~ /^.*\\([^\\]+)$/;
$server = $1;
What this does is match the string to:
starting at the beginning
"/^"
followed by 0 or more of any character
".*"
followed by a backslash
"\\"
followed by one or more non-backslash characters
"[^\\]+"
followed by the end of the string
"$/"
The non-backslash characters at the end are the "path".
Note: You should chomp before doing this!
-----Original Message-----
From: Peter Vogel [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 13, 2002 4:03 PM
To: 'Johannes Studt '; '[EMAIL PROTECTED] ';
'[EMAIL PROTECTED] '
Subject: RE: regular expression help
That only works in the "path" part doesn't contain "\". For example, this
is a valid UNC path:
\\server\share\subdir1\subsubdir1
Your suggestion would only get server and share.
-Peter
-----Original Message-----
From: Johannes Studt
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: 5/13/2002 3:52 PM
Subject: RE: regular expression help
> Let's say that I'm given \\Server\Pathname as a text. How would I
extract
> "\\Server" from this and store it to a variable $server?
$str = '\\server\path';
(undef, $server, $path) = split (/\\/, $str);
print 'Server=', $server, ' Path=', $path;
Johannes
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs