<p>I want to use regex for path of Ingress in Kubernetes to match strings starting with <code>/app</code> but not starting with <code>/app/api</code>.</p>
<p>My application in fact is in <code>/app</code> prefix and the back end part has prefix <code>/app/api</code> and now I want to match all requests related to my application but do not belong to back end (which should go to front end part).
For this, I know that the PCRE regex is <code>/app(/|$)(?!api)(.*)</code>. <strong>But</strong> in the <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/#regular-expression-support" rel="nofollow noreferrer">documentations</a> of Ingress Kubernetes, it is mentioned that it supports <a href="https://github.com/google/re2/wiki/Syntax" rel="nofollow noreferrer">RE2 Syntax</a> which seems that doesn't support negative look-ahead (and many other features). How else I can specify this regex? or what other options do I have?</p>

Ali Khalili
<p>Just define both ingress objects - the one for the backend and the one for the frontend (you can even use prefix notation here). The <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/#path-priority" rel="nofollow noreferrer">path priority rules</a> will order these entries accordingly.</p>
<p>Something like this should work:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress-1
spec:
  rules:
  - host: test.com
    http:
      paths:
      - path: /app/api
        backend:
          serviceName: backend-service
          servicePort: 80
      - path: /app
        backend:
          serviceName: frontend-service
          servicePort: 80
</code></pre>
