title: How to get path segments from calling URL including forward slash via RegEx? - ASP.NET Core
body: <p><strong>Edit:</strong>
  I need to re-open my question because it is not a RegEx Problem! The problem resides in the forward slash. Even if the RegEx matches I won't get the desired result in my controller action. ASP.NET Core does not map path segments if they contain a forward slash. And I'm looking for a workaround in terms of a middleware, routing options, whatever exists.</p>
  <p>I'm looking for a solution to get several path segments from the calling url within my controller action including the forward slash via RegEx constraint.</p>
  <p><strong>Example:</strong></p>
  <p>The user calls: <code>PUT api/v1/model/elements/elementCollection1/subElement1/subSubElement2/value</code></p>
  <p>Now everything between <code>elements/</code> and <code>/value</code> shall be passed to an action parameter called <code>elementPath</code> in a function like...</p>
  <pre><code>[HttpPut(&quot;api/v1/model/elements/{elementPath}/value&quot;)]
  public IActionResult PutElementValue(string elementPath, [FromBody] Value value)
  {
      //Here is code
  }
  </code></pre>
  <p>Do you have an idea how to RegEx and map tge match to the elementPath parameter including forward slash? Something like:</p>
  <p><code>[HttpPut(&quot;api/v1/model/elements/{elementPath:regex(&lt;Here shall be the right RegEx&gt;)}/value&quot;)]</code></p>
  <p>It's worth notice that I tried also with * catch-all parameters and it was kind of a hack but it worked for a moment. The problem is that I have another Put-Operation on api/v1/model/elements/{elementPath} without the &quot;/value&quot; appendix. Hence I'm forced to get the elementPath the right way. Plus I want to auto-generate a Swagger Doc from the Controller and everything inside and hacks are not parsed.</p>
  <p>Please help and excuse me - this is my first question on StackOverflow.</p>