Forum Discussion
String glob match for dash or hyphen
Having a probem matching a dash/hyphen in a glob string match inside a switch
I tried the classic TCL way to do it which seemed to be to have the hyphen be leading or trailing so it is not seen as a range character, but that is not working in 11.x. Also tried escaping the a trailing dash which also did not work. Looking back at the TCL docs maybe the leading/trailing dash only applies to regex and not glob string?
Originally tried this which did not work
switch -glob [string tolower [getfield [HTTP::host] ":" 1]] {
"[pid][re2][do-]*tools-config.acme.com" {
log local0. "[IP::client_addr]~[HTTP::host]:[TCP::local_port clientside]~[HTTP::uri]"
}
}
Then i tried this which also did not work
switch -glob [string tolower [getfield [HTTP::host] ":" 1]] {
"[pid][re2][do-]*tools-config.acme.com" {
log local0. "[IP::client_addr]~[HTTP::host]:[TCP::local_port clientside]~[HTTP::uri]"
}
}
Then I ended up working around the problem with this. So my prefix filter is not as good as intended in this workaround.
switch -glob [string tolower [getfield [HTTP::host] ":" 1]] {
"[pid][re2]*tools-config.acme.com" {
log local0. "[IP::client_addr]~[HTTP::host]:[TCP::local_port clientside]~[HTTP::uri]"
}
}
So glob string matching on literal dash/hyphen is still needed. Any ideas?
Thanks Matt
I am scratching my head trying to see the difference between the first two examples?
However this expression should do the trick...
"[pid][re2][do--]*tools-config.acme.com"
- Kevin_Davies_40Nacreous
I am scratching my head trying to see the difference between the first two examples?
However this expression should do the trick...
"[pid][re2][do--]*tools-config.acme.com"
- Matt_Breedlove_NimbostratusThank you Kevin. Yes that worked, doubling the dashes at the end of the line gave me a literal dash : ) It would be great if this information was in the string/glob wiki page
- Kevin_Davies_40NacreousI actually couldn't find this information anywhere myself and I looked. I just guessed. Programatically whenever there is a character that has a special meaning, there must always be a way to negate that special meaning. The two most common are using a backslash in front or using two of them in a row.
Recent Discussions
Related Content
* 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