Grab only URI

Is there a way to grab only the URI portion of a specific header? for example:

Diversion: sip:+16464540636@192.168.15.80:5060;privacy=off; reason=unconditional; counter=1.

I only want this part:

sip:+16464540636@192.168.15.80:5060

I know I can do something like: (example only numbers don’t match)

exten => _+1NXXNXXXXXX,n,Set(PAI1=${SIP_HEADER(Diversion):0:15})
exten => _+1NXXNXXXXXX,n,Set(PAI2=${SIP_HEADER(Diversion):16})
exten => _+1NXXNXXXXXX,n,SIPAddHeader(P-Asserted-Identity: ${PAI1}${PAI2})

But this does not help me if the char length is unknown.

Use regular expressions.

Thank you David, I apologize, but could you give me an example of what you reference?

Looks like it isn’t as powerful as I thought. Unfortunately they are processed with REG_NOSUB set.

You might be able to do something with ${SHELL()}, and /usr/bin/expr.

You can use a couple of CUTs to get what you want.

same => n,Set(H=${SIP_HEADER(Diversion)})
same => n,Set(PHASE1=${CUT(H, ,2)})
same => n,Set(URI=${CUT(PHASE1,;,1)})