| Author |
How to take apart the filepath using regular expression?
|
|
|
| I have a Path link with whitespace \Inetpub\wwwroot/Mail Group
How can I use regular expression to take it apart?
I try to use ($host,
$Firstfile)=($pathlink=~m|([/^\Inetpub/]+)(\S*)$|), but seems it failed
because of the whitespace between Mail Group.
Can someone kindly help me to solve this annoying problem?
Thank you so much in advance.
| |
| usenet@DavidFilmer.com 2006-01-26, 9:55 pm |
| Marco wrote:
> How can I use regular expression to take it apart?
Why would you want to?
#!/usr/bin/perl
use File::Basename; # Standard module included in Perl
my $filename = '\Inetpub\wwwroot/Mail Group';
my ($name, $path) = fileparse($filename,@suffixlist);
print "$name\n$path\n";
__END__
--
http://DavidFilmer.com
| |
| usenet@DavidFilmer.com 2006-01-26, 9:55 pm |
| use...@DavidFilmer.com wrote:
> my ($name, $path) = fileparse($filename,@suffixlist);
Oops - leave the suffixlist off since you don't care about that; so
make it:
my ($name, $path) = fileparse($filename);
| |
| Xicheng 2006-01-26, 9:55 pm |
| Marco wrote:
> I have a Path link with whitespace \Inetpub\wwwroot/Mail Group
> How can I use regular expression to take it apart?
> I try to use ($host,
> $Firstfile)=($pathlink=~m|([/^\Inetpub/]+)(\S*)$|), but seems it failed
> because of the whitespace between Mail Group.
> Can someone kindly help me to solve this annoying problem?
> Thank you so much in advance.
If you want to separate "Mail Group" with "\Inetpub\wwwroot", then you
can do:
$_ = q(\Inetpub\wwwroot/Mail Group);
($a,$b) = m{^(.*)/([^/]*)$};
# $a = '\Inetpub\wwwroot' $b = 'Mail Group'
Xicheng
| |
|
| thank you so much....it did work....really appreciate for that. :)
| |
|
| thank you .....David & Xicheng..you guys are genius........thanks
again.....
| |
|
| one more question.....
\Inetpub\wwwroot/Mail Group/Customer Email
Is it possible that separate it like:
(1) Inetpub
(2) wwwroot/Mail Group
and keep take apart it like
(1)wwwroot
(2)Mail Group/Customer Email
I just want to take \Inetpub\wwwroot/ away the keep the rest.....thank
you so much in advance....
| |
| Xicheng 2006-01-26, 9:55 pm |
| Marco wrote:
> one more question.....
> \Inetpub\wwwroot/Mail Group/Customer Email
>
> Is it possible that separate it like:
> (1) Inetpub
> (2) wwwroot/Mail Group
$_=q(\Inetpub\wwwroot/Mail Group/Customer Email);
my ($a,$b)=m{^\\(.*?)\\(.*)/.*$};
print "$a\n$b";
> and keep take apart it like
>
> (1)wwwroot
> (2)Mail Group/Customer Email
$_=q(\Inetpub\wwwroot/Mail Group/Customer Email);
my ($a,$b)=m{^.*\\([^/]*?)/(.*)$};
print "$a\n$b";
> I just want to take \Inetpub\wwwroot/ away the keep the rest.....thank
> you so much in advance....
my ($a)=m{^[^/]*?/(.*)$};
print $a;
you may take a look at something about greedy/non-greedy and regex
character class.
Good luck,
Xicheng
| |
|
| Hi Xicheng
It worked perfect. thank you so much....really appreciate for your
kindly help. thank you again..
| |
|
| Hi Xicheng
It worked perfect. thank you so much....really appreciate for your
kindly help. thank you again..
|
|
|
|