Balaji thoguluva wrote:
> I am a novice to perl programming. When I execute the following code, I get
> always "No Match". I guess my reg-exp is correct.
I also tried changing $line= "INVITE sip:[EMAIL PROTECTED] SIP/2.0"; to have double
quotes and a backslash char before @ symbol.
Even then it gives me No Match. I appreciate your help.
>
> #!/usr/bin/perl -w
> my $line= 'INVITE sip:[EMAIL PROTECTED] SIP/2.0';
> if($line =~ /^\s*(\w+)\s*(.*)\s+(sip\/\d+\.\d+)\s*\r\n/i)
> {
> print "\nSIP Method: ",$1;
> print "\nRequest URI: ",$2;
> print "\nSIP Version: ",$3;
> }
> else
> {
> print "No Match";
> }
The string you show, as others have pointed out, has no "\r\n" terminator.
Even if you're pulling your record from a text file, Perl will try hard
to change all platforms' line terminators to a simple "\n" in the record
you actually read. And even having said that, there's no reason to match /all/
of the string if you're just extracting sub-fields: it's unlikely to help to
be told that your record doesn't actually end in /\s*\r\n/. I think your regex
should look like this:
my $line= 'INVITE sip:[EMAIL PROTECTED] SIP/2.0';
$line =~ /^\s*(\w+)\s+(.*)\s+(sip\/\d+\.\d+)/i;
print map "$_\n", $1, $2, $3;
**OUTPUT
INVITE
sip:[EMAIL PROTECTED]
SIP/2.0
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>