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

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: Regex Tutorial: POSIX Bracket Expressions

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

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 :slight_smile: layer 8 problems are always the best.

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