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

Sam_Pickles_110's avatar
Sam_Pickles_110
Icon for Nimbostratus rankNimbostratus
Jun 10, 2013

stream expression regex "-" character

hi devcentral gurus;

 

I am looking to match a regular expression against a filename, which may contain a-z, A-Z, 0-9, _,-, characters before the dot.extension.

 

My regex works great for all of the above except the "-" hyphen. Can anyone see where the issue lies?

 

STREAM::expression {@filename="[\w\-]{1,200}\.[a-zA-Z0-9]{1,10}"@

 

matches filename="test_1.html" but doesnt match filename="test-1.html".

 

thanks, Sam

 

 

4 Replies

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hey Sam,

     

     

    You shouldn't need to escape characters in a character class. The hyphen needs to be the first or last character in a character class so it's not interpreted as part of a character range. Here's a related article: http://www.regular-expressions.info/posixbrackets.html

     

     

    Can you try this?

     

     

    STREAM::expression {@filename="[\w-]{1,200}\.[a-zA-Z0-9]{1,10}"@something@}

     

     

    Aaron
  • Thanks Aaron, but it still doesn't match unfortunately. I'll open a case with support;

     

     

    regards, Sam
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Sounds good. It seems like it might be a bug as both work in tclsh:

     

     

    % regexp {filename="[\w-]{1,200}\.[a-zA-Z0-9]{1,10}"} {filename="test-1.html"}

     

    1

     

    % regexp {filename="[\w\-]{1,200}\.[a-zA-Z0-9]{1,10}"} {filename="test-1.html"}

     

    1

     

     

    Or is there something different about the response which contains test-1.html? Is it possible that it's compressed or chunked?

     

     

    Aaron
  • Aaron, thanks for your help. I found the issue was no bug... I have two copies of the irule with the same name in different partitions, and was modifying the wrong one :-) layer 8 problems are always the best.

     

     

    For the record, both stream expressions work perfectly, both escaped and unescaped hyphen.