Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex insertion

Reply
Thread Tools

Regex insertion

 
 
sil
Guest
Posts: n/a
 
      07-18-2007
I need a regex of sorts that will replace ONLY the line: P-Asserted-
Identity: <sip:+$fU@$tU;user=phone> with:
P-Asserted-Identity: <sip:19998887777@1.2.3.4:5060> (from line 1)

Here is my data:

f:"Operations"<sip:
19998887777@1.2.3.4:5060>;tag=3933ee6e1923de3601d9 dab88b1dc4bf
t:<sip:(E-Mail Removed)>
m:<sip:0-d03365c213c46d247564@6.7.8.9:5060;transport=udp>
i:bf52f59d069087948090769a8a98fcdd-469d50d7@1.2.3.4
CSeq:21796 INVITE
User-Agent: Asterisk PBX
Max-Forwards:16
Date: Tue, 17 Jul 2007 23:29:27 GMT
Allow:INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIB E,NOTIFY
c:application/sdp
l:289
Remote-Party-ID: <sip:+$fU@$tU>;privacy=off;screen=no
P-Asserted-Identity: <sip:+$fU@$tU;user=phone>

1 will always start with "f:"

Maybe...
subst("/From: <sip.*)(@)(.*)/From: <sip:\1\2\3\r\nP-Asserted-
Identity: ?

Is there an alternative say if P-Asserted... was ALWAYS the 13th line

#!/usr/bin/perl

my $sipPacket = 1;
my @packetData = '';

while ( my $line = <> ) {

if ( $line =~ m/^From: <sip.*/ ) {

if ( $sipPacket < 1 ){
pwnPacket(@packetData);
@packetData = '';
}

$sipPacket--;
next;
}

push @packetData, $line;

}

sub pwnPacket {
if ($_[1] =~ /From: <sip.*)(@)(.*)/) {

# Confusion seeps in... How do I insert it into the 13 field...
print "From: <sip:\1\2\3\r\nP-Asserted-
Identity:";


}

So the packet would read:
f:"Operations"<sip:
19998887777@1.2.3.4:5060>;tag=3933ee6e1923de3601d9 dab88b1dc4bf
t:<sip:(E-Mail Removed)>
m:<sip:0-d03365c213c46d247564@10.101.1.20:5060;transport=ud p>
i:bf52f59d069087948090769a8a98fcdd-469d50d7@1.2.3.4
CSeq:21796 INVITE
User-Agent: Asterisk PBX
Max-Forwards:16
Date: Tue, 17 Jul 2007 23:29:27 GMT
Allow:INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIB E,NOTIFY
c:application/sdp
l:289
Remote-Party-ID: <sip:+$fU@$tU>;privacy=off;screen=no
P-Asserted-Identity: <sip:19998887777@1.2.3.4:5060>

 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      07-18-2007
sil <(E-Mail Removed)> wrote:
> I need a regex of sorts that will replace ONLY the line: P-Asserted-
> Identity: <sip:+$fU@$tU;user=phone> with:
> P-Asserted-Identity: <sip:19998887777@1.2.3.4:5060> (from line 1)


> Here is my data:


> f:"Operations"<sip:
> 19998887777@1.2.3.4:5060>;tag=3933ee6e1923de3601d9 dab88b1dc4bf
> t:<sip:(E-Mail Removed)>
> m:<sip:0-d03365c213c46d247564@6.7.8.9:5060;transport=udp>
> i:bf52f59d069087948090769a8a98fcdd-469d50d7@1.2.3.4
> CSeq:21796 INVITE
> User-Agent: Asterisk PBX
> Max-Forwards:16
> Date: Tue, 17 Jul 2007 23:29:27 GMT
> Allow:INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIB E,NOTIFY
> c:application/sdp
> l:289
> Remote-Party-ID: <sip:+$fU@$tU>;privacy=off;screen=no
> P-Asserted-Identity: <sip:+$fU@$tU;user=phone>


> 1 will always start with "f:"


> So the packet would read:
> f:"Operations"<sip:
> 19998887777@1.2.3.4:5060>;tag=3933ee6e1923de3601d9 dab88b1dc4bf
> t:<sip:(E-Mail Removed)>
> m:<sip:0-d03365c213c46d247564@10.101.1.20:5060;transport=ud p>
> i:bf52f59d069087948090769a8a98fcdd-469d50d7@1.2.3.4
> CSeq:21796 INVITE
> User-Agent: Asterisk PBX
> Max-Forwards:16
> Date: Tue, 17 Jul 2007 23:29:27 GMT
> Allow:INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIB E,NOTIFY
> c:application/sdp
> l:289
> Remote-Party-ID: <sip:+$fU@$tU>;privacy=off;screen=no
> P-Asserted-Identity: <sip:19998887777@1.2.3.4:5060>


What about something (assuming that the line break in the line
starting with 'f:' is the result of mangling by my newsreader)
as simple as

my $f;
while ( my $line = <> ) {
$f = $1 if $line =~ /^f:[^<]*<(sip:[^>]*)>;/;
$line =~ s/sip:[^>]*/$f/ if $line =~ /^P-Asserted-Identity:/;
print $line;
}
Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Regex insertion sil Perl Misc 0 07-18-2007 01:03 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments