Forum Discussion
lstewart_53611
Nimbostratus
Apr 29, 2010regex error - help?
I'm getting an error when trying to use the matches_regex operator. I think I might be using regexes that would work in perl but not in TCL. Can anyone see what's wrong with this? This is at the end of an iRule which works fine without this final elseif, and my brackets are actually balanced in the full rule:
elseif {[HTTP::host] == "hostwearelookingat.com" } {
if { [HTTP::uri] contains "/1/Kingdoms/users/"} {
set urivar
if { ! ( $urivar matches_regex ^.*?
\/1\/Kingdoms\/users/\[a-zA-Z0-9]) } {
pool kingdoms-reserved
}
else {
pool prod-platform
}
}
When I try this, I get the error:
line 38: [parse error: PARSE syntax 989 {syntax error in expression " ! ( $urivar matches_regex .*?\/1\/Kingdoms\/users/\[a-zA-Z0...": character not legal in expressions}] [{ ! ( $urivar matches_regex .*?\/1\/Kingdoms\/users/\[a-zA-Z0-9]) }]
The purpose of the rule is to match a uri of /1/Kingdoms/users/(any alphanumeric) and NOT match anything else. If someone simply has another suggestion of how to do that more simply, I'll take that, too. But I'm not sure what the issue is with my expression above. Thanks in advance.
- lstewart_53611
Nimbostratus
Additionally, I apologize for my newbish lack of indentation. I'll go find out how to do that right posthaste. - hoolio
Cirrostratus
Try wrapping the regex in curly braces to prevent the square braces in the character class from being interpreted as commands. Also, I don't think you don't need to escape the forward slashes in this. - lstewart_53611
Nimbostratus
Ah, that was it. Thanks so much. I was afraid there was some big TCL regex difference of which I was unaware. Thank you!
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