Showing results for 
Search instead for 
Did you mean: 


Modifying an incoming SIP INVITE message truncate number



I'm trying to write sip profile that truncates the 10-digit Diversion number dow to the last 4-digits and re-writes that number back into the Diversion header, but I'm not very succesful.  I've written may copy and writes to different headers, but never had a need to first truncate a part of the header and re-write.  For example (IP addresses changed for privacy):


I need the original Diversion header of

          Diversion: <sip:1234563333@;user=phone>

To be changed to:

          Diversion: <sip:3333@;user=phone>


Can someone help with the profile rule to make this happen?





VIP Mentor

Re: Modifying an incoming SIP INVITE message truncate number


This is a perfect use case for the SIP Profile Test Tool


SIP Profile 

voice class sip-profiles 1
 request INVITE sip-header Diversion modify "sip:\d*(\d{4})@" "sip:\1@"


SIP Input Message

INVITE sip:user@domain SIP/2.0
Diversion: <sip:1234563333@;user=phone>


SIP Profile Magic

INVITE sip:user@domain SIP/2.0
Diversion: <sip:3333@;user=phone>


The magic is in the regular expression matching pattern: sip:\d*(\d{4})@


Let's break that down.


First up, we have a prefix on our pattern, which if it doesn't exist, then we'll ignore the input.  This is a pretty standard way of qualifying the input.

sip: matches Diversion: <sip:1234563333@;user=phone>


Then we stipulate that the next character could be missing, but if it's present, it has to be a digit, and there could be more than on of them.

\d* matches Diversion: <sip:1234563333@;user=phone>


If you're wondering why it didn't match the entire number, it's because we then stipulate that there must be at least 4 digits in there, after those optional leading digits.

(\d{4}) matches Diversion: <sip:1234563333@;user=phone>


The parenthesis around it simply means "remember what you matched."  This is because the modify command, requires that we replace whatever we matched with something else, and we want to be able to reference something we matched; in this case, the last 4 digits.


Lastly, much like the prefix matching, we match postfix, and stipulate that the number should be followed by an at sign (@).

@ matches Diversion: <sip:1234563333@;user=phone>


Ok, this is actually the last part, we have to do the replace, on what we matched.  So we specify our prefix and postfix yet again, followed by recalling what we told the profile to remember about our match.




Anthony Holloway
Cisco Employee

Re: Modifying an incoming SIP INVITE message truncate number

(+5) Anthony.
To add to this, Inbound SIP profile manipulation was added starting IOS 15.4(2) T and XE 3.12S. If you are not on the minimum code, you cannot configure inbound SIP profile. If this is a CUBE, you can use outbound profiling without issues and without the need to upgrade code.

Nipun Singh Raghav
"We cannot solve our problems with the same thinking we used when we created them"