Re: Regex insertion



sil <dsphunxion@xxxxxxxxx> 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@xxxxxxx:5060> (from line 1)

Here is my data:

f:"Operations"<sip:
19998887777@xxxxxxx:5060>;tag=3933ee6e1923de3601d9dab88b1dc4bf
t:<sip:12223334444@xxxxxxxxxxxxxxxxxx>
m:<sip:0-d03365c213c46d247564@xxxxxxx:5060;transport=udp>
i:bf52f59d069087948090769a8a98fcdd-469d50d7@xxxxxxx
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,SUBSCRIBE,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@xxxxxxx:5060>;tag=3933ee6e1923de3601d9dab88b1dc4bf
t:<sip:12223334444@xxxxxxxxxxxxxxxxxx>
m:<sip:0-d03365c213c46d247564@xxxxxxxxxxx:5060;transport=udp>
i:bf52f59d069087948090769a8a98fcdd-469d50d7@xxxxxxx
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,SUBSCRIBE,NOTIFY
c:application/sdp
l:289
Remote-Party-ID: <sip:+$fU@$tU>;privacy=off;screen=no
P-Asserted-Identity: <sip:19998887777@xxxxxxx: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 ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Regex insertion
    ... I need a regex of sorts that will replace ONLY the line: ... User-Agent: Asterisk PBX ... push @packetData, $line; ...
    (comp.lang.perl.misc)
  • Re: sscanf question
    ... CSeq: 244 REGISTER ... User-Agent: Asterisk PBX ... Expires: 3600 ...
    (comp.lang.c)
  • Regex insertion
    ... I need a regex of sorts that will replace ONLY the line: ... User-Agent: Asterisk PBX ... push @packetData, $line; ...
    (comp.lang.perl.misc)
  • sscanf question
    ... CSeq: 244 REGISTER ... User-Agent: Asterisk PBX ... Expires: 3600 ...
    (comp.lang.c)