title: How to make a part of URL as optional in asp.net core 3+ web api and regex route attribute?
body: <p>I am using the following regex in route and I want to support these routes</p>
  <ul>
  <li>/en-gb/api/cat/...</li>
  <li>/th-th/api/cat/...</li>
  <li>/api/cat/...</li>
  </ul>
  <p>I am not able to support the URL path without locale i.e <code>/api/cat/...</code> I tried to put the locale part in my regex as option by using <code>?</code>. I tried in regex 101 and tested my regex it works fine (Note [ and { becomes [[ and {{ in .net core API routes)</p>
  <pre><code>[ApiController]
  [Route(&quot;/{url:regex([[a-zA-Z]]{{2}}-[[a-zA-Z]]{{2}})?}/api/cat/&quot;)]
  public class CatApiController : ControllerBase
  </code></pre>
  <p>This looks like a basic usecase, but I am not able to figure it out. Can someone please help guide me on this.</p>
  <p>EDIT -</p>
  <p><code>[Route(&quot;{locale?}/api/cat/&quot;)]</code></p>
  <p>I also try this, but it does not work for the URL without locale, even after making the locale optional.</p>