Forum Discussion
Sam_Pickles_110
Nimbostratus
Jun 09, 2013stream 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
Cirrostratus
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 - Sam_Pickles_110
Nimbostratus
Thanks Aaron, but it still doesn't match unfortunately. I'll open a case with support;
regards, Sam - hoolio
Cirrostratus
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 - Sam_Pickles_110
Nimbostratus
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.
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