简体   繁体   中英

Regular expression: match everything except *.TMP

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 (az 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 ;-)
if (!filename.endsWith(".TMP")) {
     /* then we found a match without using regExp */
}
"(?<!\\.TMP)\\Z"

读取:“ .TMP”以外的其他内容,后跟字符串的末尾。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM