Forum Discussion
Mike_S_64601
Nimbostratus
Apr 11, 2007Problem using regexp - syntax error on [
First time attempting to use a regexp in an irule; running into a syntax error in this script:
when HTTP_REQUEST {
if { [HTTP::uri] matches_regex "^\/[a-zA-Z][a-zA-Z]\/" } {
pool pool1
} else {
pool pool2
}
}
I get a syntax error on the expression:
line 2: [undefined procedure: a-zA-Z] [a-zA-Z]
Basically I want to use pool1 if the request path starts with a two-letter directory, and use pool2 if the path starts with anything else.
Is this the best way? What am I doing wrong in the matches_regex syntax?
Thanks for any assistance!
3 Replies
- TCL uses brackets to denote procedure execution. You'll need to escape the brackets.
when HTTP_REQUEST { if { [HTTP::uri] matches_regex "^\/\[a-zA-Z\]\[a-zA-Z\]\/" } { pool pool1 } else { pool pool2 } }
-Joe - hoolio
Cirrostratus
Else, I think you could use the wildcards (? or [chars]) available in TCL's string match command for a lighter weight comparison:
string match pattern string
See if pattern matches string; return 1 if it does, 0 if it doesn't. Matching is done in a fashion similar to that used by the C-shell. For the two strings to match, their contents must be identical except that the following special sequences may appear in pattern:
*
Matches any sequence of characters in string, including a null string.
?
Matches any single character in string.
[chars]
Matches any character in the set given by chars. If a sequence of the form x-y appears in chars, then any character between x and y, inclusive, will match.
\x
Matches the single character x. This provides a way of avoiding the special interpretation of the characters *?[]\ in pattern.
Aaron - Mike_S_64601
Nimbostratus
Excellent - thank you both very much!
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
