Forum Discussion
Robert_47833
Altostratus
Apr 19, 2011question about :matches_regex
Hi,met trouble in matches_regex  now
difference in expressions below
set uri [HTTP::path]
{$uri matches_regex "^/(cjj)"} { pool cjj01-BRO }
{$uri matches_regex "^/cjj"} { pool cjj01-WSE }
If I wanna visit http://10.1.1.1/cjjtext&hh1 so the &uri should be cjjtext&hh1
1:Will this uri match ^/cjj or another one
2:which uri will match "^/(cjj)" ,actually I don't understand the () here
Can someone help me in this issue
8 Replies
- hoolio
Cirrostratus
Hi,
I think both of those regexes would have the same exact matching. The parentheses would capture a match into a backreference which wouldn't be usable. If you wanted to match a literal ( or ), I think you'd need to escape them with backslashes.
Regardless, if you're just trying to check if the URI starts wtih /cjj or /(cjj), you could use a string pattern instead. This would be significantly more efficient than a regex.switch -glob [HTTP::path] { "/(cjj)*" { pool cjj01-BRO } "/cjj*" { pool cjj01-WSE } }
Aaron - Robert_47833
Altostratus
Thanks for your answer
"The parentheses would capture a match into a backreference which wouldn't be usable. "
can you give me an example to make me understand this better
you mean a variable?
like $cjj ,and this cjj is set an value at the begining of the irule
($cjj) - hoolio
Cirrostratus
Normally you could use a capturing group defined by the expression in the parentheses to capture the matched characters. Here's an example:
regexp -inline {test([0-9]} "test321654654" original match
$original would be set to the original string of test321654654 and $match would be set to 321654654. See the TCL wiki page for regexp for details: http://www.tcl.tk/man/tcl8.4/TclCmd/regexp.htm
In your example, matches_regex doesn't support saving the matches. And it's much more efficient to use a string function to do the HTTP path checking anyhow.
Aaron - Robert_47833
Altostratus
oh
got it
It is not me who use this matches_regex
Another engineer use this and I need to maintanian this irule ,but confused by ()
So you mean we use a capturing group by the expression in () to capture the matched characters
for example ([0-9]) test321654654
so 321654654 will be captured to $match
and if I use () in matches_regex ,because matches_regex doesn't support saving the matches,so it is useless.it will only work like a normal character without ()
I mean matches_regex will ignore () in my case
right? - hoolio
Cirrostratus
That's it exactly. I'd still suggest using a switch statement instead of a regex.
Aaron - Robert_47833
Altostratus
we will ,haha
but this irule is commerical ,should replace it later
so matches_regex will cost more bigip resource?like CPU or memory?
right? - Robert_47833
Altostratus
it is so late in USA,you are still up
haha
you have high spirits in respecting work - hoolio
Cirrostratus
matches_regex will cost more in CPU than a string function like switch.
Aaron 
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