Can you try
if ( $projet =~ /^([EMAIL PROTECTED])@/ ) {
$provb = $1
}
You will collect all characters from the beginnning to the first '@'.
If The first character is a '@' you will obtain an empty string.
If the first character is a '@' and you want to exclude this case use
'^([EMAIL PROTECTED])@ to obtain a result only if there is at least one character
before the first '@'.
Sayed, Irfan (Irfan) a écrit :
Can somebody please help me on following doubt.....
--Irfan.
-----Original Message-----
From: Sayed, Irfan (Irfan)
Sent: Friday, October 19, 2007 4:49 PM
To: 'Siva Prasad'
Subject: RE: Regular expression
But still my doubt exist. How Perl knows that it has to stop at the @
character
As per your suggestion , I have written like this.
my $project="aic_8.0wewew@/vobs/pvob_aic";
print "$project\n";
my ($pvob) = ($project =~ m{(.+@)});
print "$pvob\n";
and now it is taking @ in output so now how Perl knows that it has to
stop at @ character.
As per my understanding, (.+) this means any character with any no. of
times then why it is not taking all the character.
why the output is not coming as "aic_8.0wewew@/vobs/pvob_aic" and why it
is coming as aic_8.0wewew@
Please help.
Regards
Irfan.
-----Original Message-----
From: Siva Prasad [mailto:[EMAIL PROTECTED]
Sent: Friday, October 19, 2007 4:15 PM
To: Sayed, Irfan (Irfan)
Subject: RE: Regular expression
This is because you have given @ outside () and the string that is there
inside the '()' is moved to $pvob.(i..e the first matched string in the
right hand side is moved into the first variable on the left hand side.
Try this by giving '@' inside the '()' the you will also get '@' in
pvob.
'()' tells the first matched string.
Tyr the below
my $string="aic_8.0@/vobs/pvob_aic";
my $pvob = ($string =~ m{(.+)@});
print "$1\n";
$1 represents string that is matched inside the first '()' occurrence.
Thanks,
Siva
-----Original Message-----
From: Sayed, Irfan (Irfan) [mailto:[EMAIL PROTECTED]
Sent: Friday, October 19, 2007 4:01 PM
To: beginners@perl.org
Subject: Regular expression
Hi All,
I have one string aic_8.0@/vobs/pvob_aic which is stored in one variable
$project
Now I need only that part of that string which is before @ so I have
written following regular expression to achieve this...
my ($pvob) = ($project =~ m{(.+)@}); and with the help of this reg. exp.
I am achieving the expected result as aic_8.0
but my doubt is that how Perl knows that it has to stop collecting all
the characters till @ character comes and don't include @ character in
output
Please help.
Regards
Irfan.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/