Forum Discussion
GavinW_29074
Dec 08, 2011Nimbostratus
Extract value from VirtualName
Hi there,
I'm trying to write an iRule condition that needs to know part of the [Virtual Name] value...
A couple of examples are:
/Common/Test.App/app.test.com_https
/Common/app2.test.co...
hooleylist
Dec 08, 2011Cirrostratus
Hi Gavin,
Your scan pattern of %*[^/]/%[^_] would not work because all virtual server names in 11.x will start with a /. I don't think you can use scan alone to match a variable number of subfolders.
Also, with scan, you can check the number of matches before trying to use one of the match variables:
if {[scan $virtualname {%*[^/]/%[^_]} vname] == 1}{
log local0. "Matched $vname from $virtualname"
} else {
log local0. "Couldn't parse $virtualname"
}
Here are three ways to do it. The string commands are more complicated but also more efficient than the single regexp. I'd guess the second option is most efficient, but you could use timing to test this:
http://devcentral.f5.com/wiki/iRules.timing.ashx
scan [string range [virtual name] [expr {[string last / [virtual name]] +1}] end] {%[^_]%*s} vs_name
log "scan: $vs_name"
set vs_name [findstr [string range [virtual name] [string last / [virtual name]] end] "/" 1 "_"]
log "findstr: $vs_name"
regexp {(/.*/)?[^_]+} [virtual name] unused unused vs_name
log "regexp: $vs_name"
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