[SR-Users] Regex not capturing as required for subst_hf

Salvinder Parhar salvinder.parhar09 at gmail.com
Fri Nov 25 22:15:18 CET 2022


Hi,

I'm trying to capture and substitute the host IP of contact header using
the subst_hf but it's not working as expected. I tested my regex in a
tester and it works fine there but not in the Kamailio config.

Regex: @(.+?)>

Substitution: @PUBLIC_IP:5060>

Three contact headers that I'm trying to match;

Contact:<sip:0065*7766 at 172.16.1.217:5060
>;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"

Contact: <sip:0065*7788 at 172.16.1.216
;transport=udp>;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"

Contact: <sip:0925*0007 at 172.16.1.218:5060>

Outcome I'm expecting for the three contact headers;

Contact:<sip:0065*7766 at PUBLIC_IP
:5060>;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"

Contact: <sip:0065*7788 at PUBLIC_IP
:5060>;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"

Contact: <sip:0925*0007 at PUBLIC_IP:5060>

This regex in Kamailio works fine for the first and third contact header
but for the second contact header it matches all the way to the end of the
contact header excluding the quote (") sign. I've tried so many other
combinations [like @(.+?)>;? ] of regex but nothing seems to work.

Is there a way to accomplish this with one regex?

Thanks,
Sal

On Fri, 25 Nov 2022 at 16:10, Salvinder Parhar <salvinder.parhar09 at gmail.com>
wrote:

> Hi,
>
> I'm trying to capture and substitute the host IP of contact header using
> the subst_hf but it's not working as expected. I tested my regex in a
> tester and it works fine there but not in Kamailio config.
>
> *Regex:* @(.+?)>
>
> *Substitution:* @PUBLIC_IP:5060>
>
> *Three contact headers that I'm trying to match;*
>
> Contact:<sip:0065*7766 at 199.48.100.166:5060
> >;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"
>
> Contact: <sip:0065*7788 at 172.16.1.216
> ;transport=udp>;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"
>
> Contact: <sip:0925*0007 at 199.48.100.166:5060>
>
> *Outcome I'm expecting for the three contact headers;*
>
> Contact:<sip:0065*7766*@PUBLIC_IP:5060>*
> ;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"
>
> Contact: <sip:0065*7788*@PUBLIC_IP:5060>*
> ;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"
>
> Contact: <sip:0925*0007*@PUBLIC_IP:5060>*
>
> This regex in Kamailio works fine for the first and third contact header
> but for the second contact header it matches all the way to the end of the
> contact header excluding the quote (") sign. I've tried so many other
> combinations [like *@(.+?)>;?* ] of regex but nothing seems to work.
>
> Is there a way to accomplish this with one regex?
>
> Thanks,
> Sal
>
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20221125/7bf813e8/attachment.htm>


More information about the sr-users mailing list