Forum Discussion
Anthony_Porcano
Nimbostratus
Apr 15, 2007matches_regex and matchclass
Is there any way to apply a regular expression to matchclass? Apologies in advance if I'm missing something obvious here, but my attempts thus far are not working.
if { [ matchclass [HTTP::path] matches_reqex "\/portal\/($::flaggedpaths)\?" ] } {
log local0. "matched [HTTP::path] in flaggedpaths class"
}
Returns:
[invalid option "matches_reqex" must be: contains ends_with equals starts_with] [matches_reqex]
The error seems clear enough. You can only use a subset of the available relational operators with the matchclass command. Am I interpretting this correctly? Is there another way to accomplish pattern matching against a class?
Thanks in advance,
Anthony
1 Reply
- Unfortunately, as you've found out, matchclass is limited to only the operators listed in that error. But, you aren't completely stuck. While it's not as elegant as a single matchclass line, classes are interpreted as TCL lists, so you can use the TCL list commands to loop through the elements and do whatever you want.
This should be equivalent (or close to it).when HTTP_REQUEST { foreach path $::flaggedpaths { if { [HTTP::path] starts_with "/portal/$path" } { log local0. "matched [HTTP::path] in flaggedpaths class member '$path'" break } } }
You could have used a matches_regexp but I went with the string comparison approach as that avoids the overhead associated with the regular expression comparison.
And, yes, it goes both ways with matchclass. You can also pass in a user created TCL lists instead of a class if you so desire...
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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