Apache2 Regular Expression Optional Capture Group
<p>Need help with a problem that has been bothering me for some time!</p>

<p>I am attempting to create an Apache <code>AliasMatch</code> Regular Expression that will match a URL. The Issue I'm having is that I am using the capture groups as variables <code>$0 $1 $2</code> within the file match portion. Essentially I need to capture the <code>path/to/controller</code> portion of the url to actually grab my file and I wish to not use any capture groups after and including the double forward slashes.</p>

<p><a href="http://domain.com/etc/xx/abc/" rel="nofollow">http://domain.com/etc/xx/abc/</a><strong>path/to/controller</strong>//myDesiredMVCAction</p>

<p>The issue Essentially is that with the following expression:</p>

<p><code>^/etc/(xx|yy)/(abc|xyz)/(.*)(?=//)(.*)</code></p>

<p>it only matches</p>

<p><code>http://domain.com/etc/xx/abc/path/to/controller//myDesiredMVCAction</code></p>

<p>and not:</p>

<p><code>http://domain.com/etc/xx/abc/path/to/controller</code></p>

<p>given that the double slashes and everything trailing it is optional.</p>

<p>So when I make the regex expression optional by appending a <code>?</code> it ruins the capture group by including the <code>//myDesiredMVCAction</code> portion..</p>

<p><code>^/etc/(xx|yy)/(abc|xyz)/(.*)(?=//)(.*)?</code></p>

<p>It is possible to achieve what I'm after?</p>