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

Daniel-Constantin Mierla miconda at gmail.com
Mon Nov 28 10:50:04 CET 2022


Hello,

it is quite common to have a lookahead approach to match the longest
value, which looks like happening in your case for 2nd contact header.
We just leverage the libc regex functions, it is not a custom
implementation in Kamailio.

You should try to exclude having > in .+ matched value, maybe with a
regexp like:

@([^>]+)>

Cheers,
Daniel

On 25.11.22 22:15, Salvinder Parhar 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 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
> <http://7766@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 <http://0007@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
>     <http://7766@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
>     <http://0007@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
>
>
>
>     *
>     *
>     *
>     *
>
>
>
> __________________________________________________________
> Kamailio - Users Mailing List - Non Commercial Discussions
> sr-users at lists.kamailio.org
> Important: keep the mailing list in the recipients, do not reply only to the sender!
> Edit mailing list options or unsubscribe:
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20221128/6d6e730d/attachment.htm>


More information about the sr-users mailing list