<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>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.</p>
    <p>You should try to exclude having > in .+ matched value, maybe
      with a regexp like:</p>
    <p>@([^>]+)></p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 25.11.22 22:15, Salvinder Parhar
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAG8SwHAXzbiPU=2V=PGSvKcOhOS3ksGa_aiXh7rQGbbyyvHGrQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Hi,<br>
        <br>
        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.<br>
        <br>
        Regex: @(.+?)><br>
        <br>
        Substitution: @PUBLIC_IP:5060><br>
        <br>
        Three contact headers that I'm trying to match;<br>
        <br>
        Contact:<<a class="moz-txt-link-freetext" href="sip:0065*">sip:0065*</a><a href="http://7766@172.16.1.217:5060"
          moz-do-not-send="true">7766@172.16.1.217:5060</a>>;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"<br>
        <br>
        Contact: <<a class="moz-txt-link-freetext" href="sip:0065*">sip:0065*</a><a href="mailto:7788@172.16.1.216"
          moz-do-not-send="true" class="moz-txt-link-freetext">7788@172.16.1.216</a>;transport=udp>;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"<br>
        <br>
        Contact: <<a class="moz-txt-link-freetext" href="sip:0925*">sip:0925*</a><a href="http://0007@172.16.1.218:5060"
          moz-do-not-send="true">0007@172.16.1.218:5060</a>><br>
        <br>
        Outcome I'm expecting for the three contact headers;<br>
        <br>
Contact:<a class="moz-txt-link-rfc2396E" href="sip:0065*7766@PUBLIC_IP:5060"><sip:0065*7766@PUBLIC_IP:5060></a>;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"<br>
        <br>
        Contact:
<a class="moz-txt-link-rfc2396E" href="sip:0065*7788@PUBLIC_IP:5060"><sip:0065*7788@PUBLIC_IP:5060></a>;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"<br>
        <br>
        Contact: <a class="moz-txt-link-rfc2396E" href="sip:0925*0007@PUBLIC_IP:5060"><sip:0925*0007@PUBLIC_IP:5060></a><br>
        <br>
        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.<br>
        <br>
        Is there a way to accomplish this with one regex?<br>
        <br>
        Thanks,<br>
        Sal<br>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Fri, 25 Nov 2022 at 16:10,
          Salvinder Parhar <<a
            href="mailto:salvinder.parhar09@gmail.com"
            moz-do-not-send="true" class="moz-txt-link-freetext">salvinder.parhar09@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div dir="ltr">Hi,
            <div><br>
            </div>
            <div>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.</div>
            <div><br>
            </div>
            <div><b>Regex:</b> @(.+?)></div>
            <div><br>
            </div>
            <div><b>Substitution:</b> <a class="gmail_plusreply"
                id="m_2192040369922161123plusReplyChip-0"
                moz-do-not-send="true">@PUBLIC_IP:5060></a></div>
            <div><br>
            </div>
            <div><b>Three contact headers that I'm trying to match;</b></div>
            <div><br>
            </div>
            <div>Contact:<<a class="moz-txt-link-freetext" href="sip:0065*">sip:0065*</a><a
                href="http://7766@199.48.100.166:5060" target="_blank"
                moz-do-not-send="true">7766@199.48.100.166:5060</a>>;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"<br>
              <br>
              Contact: <<a class="moz-txt-link-freetext" href="sip:0065*">sip:0065*</a><a href="mailto:7788@172.16.1.216"
                target="_blank" moz-do-not-send="true"
                class="moz-txt-link-freetext">7788@172.16.1.216</a>;transport=udp>;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"<br>
              <br>
              Contact: <<a class="moz-txt-link-freetext" href="sip:0925*">sip:0925*</a><a
                href="http://0007@199.48.100.166:5060" target="_blank"
                moz-do-not-send="true">0007@199.48.100.166:5060</a>><br>
            </div>
            <div><br>
            </div>
            <div><b>Outcome I'm expecting for the three contact headers;</b></div>
            <div><br>
            </div>
            <div>Contact:<<a class="moz-txt-link-freetext" href="sip:0065*7766">sip:0065*7766</a><a class="gmail_plusreply"
                id="m_2192040369922161123gmail-plusReplyChip-0"
                moz-do-not-send="true"><b>@PUBLIC_IP:5060></b></a>;methods="INVITE,ACK,BYE,CANCEL,OPTIONS,INFO,MESSAGE,SUBSCRIBE,NOTIFY,PRACK,UPDATE,REFER"<br>
              <br>
              Contact: <<a class="moz-txt-link-freetext" href="sip:0065*7788">sip:0065*7788</a><a class="gmail_plusreply"
                id="m_2192040369922161123gmail-plusReplyChip-0"
                moz-do-not-send="true"><b>@PUBLIC_IP:5060></b></a>;expires=3600;reg-id=1;+sip.instance="<urn:uuid:03660bc5-bb70-4784-8ac5-000413B108BA>"<br>
              <br>
              Contact: <<a class="moz-txt-link-freetext" href="sip:0925*0007">sip:0925*0007</a><a class="gmail_plusreply"
                id="m_2192040369922161123gmail-plusReplyChip-0"
                moz-do-not-send="true"><b>@PUBLIC_IP:5060></b></a><br>
            </div>
            <div><br>
            </div>
            <div>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 <b>@(.+?)>;?</b> ] of regex but
              nothing seems to work.</div>
            <div><br>
            </div>
            Is there a way to accomplish this with one regex?
            <div><br>
            </div>
            <div>Thanks,</div>
            <div>Sal</div>
            <div><br>
            </div>
            <div><br>
            </div>
            <div><br>
              <a class="gmail_plusreply" moz-do-not-send="true"><b><br>
                </b></a></div>
            <div><a class="gmail_plusreply" moz-do-not-send="true"><b><br>
                </b></a></div>
            <div><br>
            </div>
            <div><br>
            </div>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a></pre>
  </body>
</html>