To do this, you'll need to use this regular expression:
foo/bar/.+?\.(?!jar).+
Explanation
You are telling it what to ignore, so this expression is searching for things you don't want.
- You look for any file whose name (including relative directory) includes (foo/bar/)
- You then look for any characters that precede a period ( .+?\. == match one or more characters of any time until you reach the period character)
- You then make sure it doesn't have the "jar" ending (?!jar) (This is called a negative look ahead
- Finally you grab the ending it does have (.+)
Regular expressions are easy to mess up, so I strongly suggest that you get a tool like Regex Buddy to help you build them. It will break down a regex into plain English which really helps.
EDIT
Hey Jason S, you caught me, it does miss those files.
This corrected regex will work for every example you listed:
foo/bar/(?!.*\.jar$).+
It finds:
- foo/bar/baz.txt
- foo/bar/baz
- foo/bar/jar
- foo/bar/baz.jar.txt
- foo/bar/baz.jar.
- foo/bar/baz.
- foo/bar/baz.txt.
But does not find
New Explanation
This says look for files in "foo/bar/" , then do not match if there are zero or more characters followed by ".jar" and then no more characters ($ means end of the line), then, if that isn't the case, match any following characters.