Forum Discussion
Cole_Libby_1665
Altostratus
Feb 06, 2007Do 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_18Historic F5 AccountHi 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
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
