Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SSI capture group result extraction

Status
Not open for further replies.

Olaf Doschke

Programmer
Oct 13, 2004
14,847
DE
Let's see if someone still is doing SSI here. Just out of curiosity I try to create a little building block templating just using SSI #includes.

Code:
<!--#set var="keyvaluepairs" value="key1=value1&key2=value2" -->
<!--#if expr="v('keyvaluepairs')=~/\bkey2=([a-zA-Z0-9]*)/" -->
<!--#set var="match" value="$0" -->
<!--#set var="key2" value="$1" -->
<!--#echo var="match" -->
<!--#echo var="key2" -->
<!--#endif -->

You can imagine finally this is about processing v('QUERY_STRING') later instead of keyvaluepairs.

I expected key1 to contain "value1" only, it should be the capturing group defined by parenthesis in the regex: ([a-zA-Z0-9]*) after the constant "key1=" part of the regex.
Instead $1 is empty.

So is there something wrong with how the current version (Apache/2.4.10) processes regex?

Bye, Olaf.

 
Hi

I did not used SSI for looong time. And a couple of versions.

So I would go the old way :
Code:
[b]SSILegacyExprParser[/b] on
Code:
<!--[b]#set[/b] var=[i]"keyvaluepairs"[/i] value=[i]"key1=value1&key2=value2"[/i] -->
<!--[b]#if[/b] expr=[i]"[highlight]$[/highlight]keyvaluepairs = /[highlight](?:^|&)[/highlight]key2=([a-zA-Z0-9]*)/"[/i] -->
<!--[b]#set[/b] var=[i]"match"[/i] value=[i]"$0"[/i] -->
<!--[b]#set[/b] var=[i]"key2"[/i] value=[i]"$1"[/i] -->
<!--[b]#echo[/b] var=[i]"match"[/i] -->
<!--[b]#echo[/b] var=[i]"key2"[/i] -->
<!--[b]#endif[/b] -->

Regarding your original code, I have no idea whether this applies to it or not :
Expressions in Apache HTTP Server said:
Regular expression backreferences

The strings [tt]$0[/tt] ... [tt]$9[/tt] allow to reference the capture groups from a previously executed, successfully matching regular expressions. They can normally only be used in the same expression as the matching regex, but some modules allow special uses.
( Expressions in Apache HTTP Server | Other | Regular expression backreferences )

Maybe is intended behavior.

Feherke.
feherke.ga
 
Thanks Feherke,

at least that works in legacy mode and since SSILegacyExprParser can be set per directory I should be able to control it.

It can't be the limitation, $0..$9 normally only are usable within the same expression. At least $0 works giving the overall match. I wonder, whether ap_expr syntax changed how capture groups have to be marked, though that should be reglar expression standard syntax.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top