tags:

views:

137

answers:

4

I'm having troubles to create a regular expression who checks if a file has the extention .TMP so the pattern should accept any string who's not equal to (a-z 0-9 or event dots).TMP

To be clear: the matcher should only be succesfull when the file doesn't have the TMP extention.

I've allready found that I need to use (?!expression) for the "not"...

(?!.*TMP]) // is wrong ;-)
+4  A: 
"(?<!\\.TMP)\\Z"

Read: something other than ".TMP" followed by the end of the string.

sepp2k
"When all you have is a regexp, every problem looks like line noise" -- me ;)
msw
@msw: The question explicitly asked for a regexp. I don't think it's fair to downvote for answering the question that was asked.
sepp2k
Agreed. It wasn't to "punish" the poster but to move the answer down the stack (which has happened naturally thus downvote removed). Indeed, the question did ask for a regexp, but sometimes the question is wrong. I don't expect you to necessarily agree with this stance, but I hope you can understand it.
msw
+2  A: 

It is not a answer of your question but I think you should look at Apache Common IO which have a bunch of simple methods which can do everything your commonly do. Including finding extensions. Then you simply make a if statement instead of a reg. exp.

http://commons.apache.org/io/

and see the specific java doc for getExtension: getExtension JavaDoc

lasseespeholt
+2  A: 

http://stackoverflow.com/questions/1061651/java-regular-expression-match-everything-but

Search before you post something! :)

pavanlimo
Although correct, IMO it would be better suited as a comment instead of an answer.
Bart Kiers
True. Noted. :)
pavanlimo
+10  A: 
if (!filename.endsWith(".TMP")) {
     /* then we found a match without using regExp */
}
Andreas_D
+1 agree, too trivial a problem to apply regular expressions to.
Adrian Regan
+1 but on OS X or Windows you might want to convert the file name to upper case before doing the comparison (case insensitive file systems).
JeremyP