This was originally reported in bug 48956, but it is a separate issue. In Apache HTTPD there is such example in documentation of mod_include: [1] [[[ <!--#if expr="$QUERY_STRING = /^sid=([a-zA-Z0-9]+)/" --> <!--#set var="session" value="$1" --> <!--#endif --> ]]] [1] http://httpd.apache.org/docs/current/mod/mod_include.html Here $1 references the value of group #1 as caught by regular expression. Example from comment 3 in bug 48956: [[[ <!--#set var="aux" value="aa12" --> <!--#if expr="$aux=/^aa([a-zA-Z0-9\-_]*)/" --> <!--#set var="aux2" value="$1" --> <!--#endif --> Resulting value:<!--#echo var="aux2" --> ]]] In Tomcat support for regular expression in SSI was added in r1136231 and r1136399 and is implemented in ExpressionParseTree$CompareNode#compareBranches() Maybe the last used Matcher can be stored in some context, so that it can be later used to resolve $1 etc. references. I do not know whether $1 is limited to that #if, or it is available everywhere later until it is overwritten by the next regexp-matching operation. I do not know how HTTPD behaves here. I think the latter would be easier to implement.
*** Bug 55176 has been marked as a duplicate of this bug. ***
I've tested httpd and the behaviour is as follows: Before any matches are attempted, $1 and friends are set to the empty string After a successful match, $1 and friends remember the contents of the group until the next match is attempted (not is successful) After an unsuccessful match, $1 and friends are set to the empty string At first glance, this looks fairly easy to implement.
Implemented in 9.0.x for 9.0.11 onwards.