Forum Discussion
GavinW_29074
Nimbostratus
Dec 08, 2011Extract 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.com_http
I want to get the bit between the last '/' and the '_'...
I've tried using the scan command as follows:
scan $virtualname {%*[^/]/%[^_]} vname
log local0. "\$vname = $vname" However I keep getting: can't read "vname": no such variable while executing "log local0. "\$vname = $vname""
Any ideas???
Or is there a better way of doing it?
Cheers
Gav
2 Replies
- hoolio
Cirrostratus
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 - GavinW_29074
Nimbostratus
Aaron
Cheers for the response.
I've set-up the second option, and it works exactly as I need it to...
Haven't done any timings on them yet, but will keep an eye on it...
Cheers
Gavin
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
