Forum Discussion

Cole_Libby_1665's avatar
Cole_Libby_1665
Icon for Altostratus rankAltostratus
Feb 06, 2007

Do non-capturing reg exp work in irules?

 

Hi,

 

 

I have a piece of code that uses a non-capturing regex. something like (?:re) It doesn't seem to work as the replacement value always has the piece i want to omit.

 

 

set find {(?:href=).*}

 

set replace {href=http://proxy.dandd.com/pxy?orig_url=http://%newhost%&}

 

set subs [regsub -all -nocase $find $payload $replace new_response]

 

 

Cole

 

1 Reply

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Hi Cole -

    That's because within a replacement string, an ampersand (&) takes on the value of the string that the regex matched, and your $replace value ends with &.

    If you intended to terminate the replacement string with a literal "&", you need to escape it:
    set replace {href=http://proxy.dandd.com/pxy?orig_url=http://%newhost%\&}

    The next problem you will run into is that the .* will match from the first "href=" to the end of the payload (greedy match), so you'll need to specify a term characer and a non-greedy wildcard. And most (all?) href target strings are surrounded with "", so you might also want to account for that.

    This should be close to what you're looking for:
    set find {(?:href=\")(.*?\")}
    set replace {href=\"http://proxy.dandd.com/pxy?orig_url=http://%newhost%}
    set subs [regsub -all -nocase $find $payload "$replace\\1" new_response] 

    HTH

    /deb