For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Anonymous's avatar
Anonymous
Feb 01, 2016

how to match "\w" with -glob to avoid using -regexp

Hi team,

I need help with iRule to filter URLs.

I want to match: /some/path/only_words-XXX or /some/path/only_words-XXXX (and everything below)

XXX and XXXX are numbers (length 3 or 4), "only_words" are any word character plus the "_" sign (or \w in regexp) and also I want the "-" sign.

Now in apache httpd I'm doing this with regexp:

RewriteCond %{REQUEST_URI} /some/path/\w+-\d{3,4}(/?).*

As regexp is not recommended I wonder how to do this using "switch -glob [HTTP::uri]"

"/some/path" is always the same.

Please advice.

Thanks

5 Replies

  • Hi Vova V,

    the

    switch -glob
    matching pattern is very limited in its capabilities. Basically this is what it could do...

    switch -glob -- [HTTP::uri] { 
        "/some/path/[A-z]-[0-9]/*" {
             This would match /some/path/a-1/file.txt or /some/path/A-2/file.txt or /some/path/_-2/file.txt but not /some/path/bb-22/file.txt
            } 
        "/some/path/[A-z][A-z][A-z]-[0-9][0-9][0-9]/*" {
             This would match /some/path/abc-122/file.txt or /some/path/a_b-321/file.txt but not /some/path/a_cd-2234/file.txt
            } 
        "/some/path/*-[0-9][0-9][0-9]/*" - "/some/path/*-[0-9][0-9][0-9][0-9]/*" {
             This would match /some/path/a_bc-123/file.txt or /some/path/ab_cd_ef-gh-1234/file.txt or /some/path/1234-1234/file.txt or /some/path/abc/a/b/c/d-123/file.txt but not /some/path/a_b-22/file.txt or /some/path/a_b-222a/file.txt
            }
        "/some/path/*/*" {
             This would match /some/path/aaa/file.txt or /some/path/123/file.txt or /some/path/abc123/file.txt but not /some/path/file.txt or /some/path2/abc_123/file.txt
            }   
        default {
             This would match everything else..
            } 
    }
    

    Cheers, Kai

  • Anonymous's avatar
    Anonymous

    I'm using now:

    "/some/path/*-[0-9][0-9][0-9]/*" - "/some/path/*-[0-9][0-9][0-9][0-9]/*" {}
    

    but as you said it will match other unwanted things.

    I was wondering if I can do something like:

    /some/path/[a-zA-Z*]-[0-9][0-9][0-9]/* - /some/path/[a-zA-Z*]-[0-9][0-9][0-9][0-9]/* {}
    

    to limit the 1st match to only word characters, any number of hits.

    • Kai_Wilke's avatar
      Kai_Wilke
      Icon for MVP rankMVP
      Unfortunately its not possible to have a -glob wildcard of unlimited_times*[a-zA-Z]. [validchars] is always just a single character wildcard... Cheers, Kai
    • Anonymous's avatar
      Anonymous
      I see.. Thanks for confirming.