From: "Irfan Sayed" <irfan_sayed2...@yahoo.com>
i have string 'c:\p4\car\abc\xyz.csproj'
i just need to match the xyz.csproj
i tried few option but does not help.
can someone please suggest
regards
irfan
my $data = 'c:\p4\car\abc\xyz.csproj';
my ( $file_name ) = $data =~ /([^\\]+)$/g;
print $file_name;
It will print:
xyz.csproj
( and ) captures the matched string but because in this case they capture
the whole regular expression, you can omit using them like:
my ( $file_name ) = $data =~ /[^\\]+$/g;
[^\\] means that it matches everything which is not a \ char, and because \
is a special char, it should be escaped with another \ before it (this is
why there are 2 \ chars).
There is a + char after the [^\\] meaning that [^\\] doesn't match just a
single char, but one or more.
And at the end there is a $ sign meaning that after this string that mached,
it is the end of the string, so this regex will match any substring which
doesn't contain a \ char which appear at the end of the string.
HTH, and of course, use strict and warnings.
Octavian
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/