Forum Discussion

David_Homoney's avatar
David_Homoney
Icon for Nimbostratus rankNimbostratus
Mar 06, 2008

Regex in STREAM

So I am attempting to use regex with the stream profile in an iRule. I need this to catch all hrefs execpt for ones with a css file extension. I have tested this with regex buddy and it looks good, but the STREAM barfs. First, here is the regex.

 

 

href="[^"]*(?

 

Finally here is the error the STREAM profile spits out.

 

 

Mar 6 13:19:56 tmm tmm[1545]: 01220005:3: Can't compile regular expression - (href="[^"]*(?:?Mar 6 13:19:56 tmm tmm[1545]: 01220001:3: TCL error: Link_Scrub_v8 - couldn't compile regular expression pattern: quantifier operand invalidIllegal argument (line 1) invoked from within "STREAM::expression {@href="[^"]*(?

 

 

Any ideas? In the first log message it shows regex code that is different when what I have and you can see that in the second message. Very weird.

4 Replies

  • Unfortunately, TCL only supports lookaheads in regexes--not lookbehinds (negative or positive). I ran into this issue this week. I ended up having to collect the response content, use a more permissive regex with the regexp command and parse the results to only replace the strings that needed to be replaced. It would have been a lot easier with lookbehinds and a stream rule. Ugh...

     

     

     

    http://www.regular-expressions.info/lookaround.html

     

     

    Finally, flavors like JavaScript, Ruby and Tcl do not support lookbehind at all, even though they do support lookahead.

     

     

     

     

    Aaron
  • Thanks hoolio, I figured you would know. Unfortunately collecting the data in this case can't be done as it is well over 2mb and causes tmm to crash. Ugh is right. One step forward, two steps back. Thanks for the info.
  • I can't really see a way of getting an exact match without lookbehinds. Maybe you can try Deb's collect/release suggestion in the codeshare (Click here). If you end up using a regex for matching links, you can use this to match more variations: (?i)href\s*=\s*(?:'|")[\w.:/]+(?:'|"). You could then add logic to update any matches which don't end in .css' or .css".

     

     

    Aaron
  • Hi Homoney,

     

     

    Better very late than never? I think using STREAM::match and STREAM::replace in the STREAM_MATCHED event would have worked for your scenario...

     

     

    Excluding some urls for the STREAM conversion (Click here)

     

     

    Aaron