Forum Discussion
Robert_47833
May 10, 2011Altostratus
confused by match_regx
Hi,can someone help?
when HTTP_REQUEST
{ default vars set in most iRules written by StubHub
set host [HTTP::host]
set uri [HTTP::path]
set subdomain1 "static"
set subdomain2 "s"
if { $host matches_regex "^$subdomain1.|$subdomain2." and ($uri matches_regex "(jpg|bmp|gif|png|img|ico|js|css|swf|swz|vbs|html|htm|csv|txt|crossdomain.xml)$")}
{ if { $uri matches_regex "^/(cswebtool|cobrands|jsrs|overflow|promotions|data|resources)" }
{ persist none
pool SRWD25-STATIC return
}
}
else { xxxxx
Now I visit
Will this match pool ddd25-STATIC
Because in my opinion,
$host matches_regex "^$subdomain1.|$subdomain2."
so it should be static.|s because "|" is contained by ""
the operator "|" means "or" or only a string?
confused again
- hooleylistCirrostratusYes, it should match as a pipe is considered a logical OR in regex. Here's a simple test to show the match:
when RULE_INIT { http://sjj-cache28.dddstatic.com/resources/flex/ticketFilter-1.10.2.swf set host sjj-cache28.dddstatic.com set uri "/resources/flex/ticketFilter-1.10.2.swf" set subdomain1 "static" set subdomain2 "s" if { $host matches_regex "^$subdomain1.|$subdomain2." and ($uri matches_regex "(jpg|bmp|gif|png|img|ico|js|css|swf|swz|vbs|html|htm|csv|txt|crossdomain.xml)$")} { if { $uri matches_regex "^/(cswebtool|cobrands|jsrs|overflow|promotions|data|resources)" }{ log local0. "matched" return } } log local0. "no match" }
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "s.*" - "static.*" { switch -glob [HTTP::path] { "*.jpg" - "*.bmp" - "*.gif" - "*.png" - "*.img" - "*.ico" - "*.js" - "*.css" - "*.swf" - "*.swz" - "*.vbs" - "*.html" - "*.htm" - "*.csv" - "*.txt" - "*.crossdomain.xml" { switch -glob [HTTP::path] { "/cswebtool*" - "/cobrands*" - "/jsrs*" - "/overflow*" - "/promotions*" - "/data*" - "/resources*" { persist none pool SRWD25-STATIC return } } } } } } }
- Robert_47833Altostratusoh,Thanks ,it seems match_regx think ^should apply to $subdomain1. and $subdomain2.
- hooleylistCirrostratusIf you want the regex to match on a string starting with $subdomain1 or $subdomain2 I think you'd need to use parentheses around them or expliclity put the caret on both:
- Robert_47833AltostratusHi,Aaron
- hooleylistCirrostratusActually, the issue seems to be that the backslash needs to be escaped. This is necessary as the regex is wrapped in double quotes. If you didn't have any variables that needed to be interpreted, you could wrap the regex in curly braces.
set host "sjj-cache28.dddstatic.com" set subdomain1 "static" set subdomain2 "s" if { $host matches_regex "^(?:$subdomain1|$subdomain2)\\." }{ log local0. "matched host check for $subdomain2 on $host" } else { log local0. "no match on host check for $subdomain2 on $host" }
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