STREAM::expression regex
I'm in the process of writing an irule to correct for some bad code in one of our applications. The app in question has multiple bad links with tildes in it.
Example bad code
img src="~/0.jpg" width="60" height="80"
img src="/images/~/1.jpg" width="60" height="80"
img src="/foo/bar/~2.jpg" width="60" height="80"
img src="/~/3.jpg" width="60" height="80"
img src="/foo/bar/~/images/4.jpg" width="60" height="80"
This should be corrected to
img src="/0.jpg"
img src="/1.jpg"
img src="/foo/bar/~2.jpg"
img src="/3.jpg"
img src="/images/4.jpg"
Note I'm not concerned about fixing this one as it should generate a 404.
img src="/foo/bar/~2.jpg"
This is a snippet of my irule
when HTTP_RESPONSE {
Disable the stream filter by default
STREAM::disable
Enable the stream filter for text responses only
if {[HTTP::header value Content-Type] contains "text"}{
Replace '".*~/' with '/'
STREAM::expression {@src="\~/@src="/@ @src="/\~/@src="/@ @src="/.*/\~/@src="/@}
Enable the stream filter for this response only
STREAM::enable
}
}
When I test my regex with expresso 'src="/.*/\~/' works fine, but I'm not able to come up with the correct regex within the irule after many variations.
Any help would be appreciated.