For this you will need to use this regular expression:
foo/bar/.+?\.(?!jar).+
Explanation
You say ignore, so this expression is looking for things that you do not need.
- You are looking for any file whose name (including the relative directory) includes (foo / bar /)
- Then you look for the characters preceding the period (. +? \. == correspond to one or more characters of any time until you reach the period character)
- Then you will make sure that it has no end to "jar" (?! Jar) (This is called a negative look ahead
- Finally, you will get the ending that he has (. +)
Regular expressions are easy to spoil, so I highly recommend that you get a tool like Regex Buddy to help you create them. It will break the regular expression into plain English, which really helps.
EDIT
Hey Jason S , you caught me, he skips these files.
This fixed regular expression will work for every example you give:
foo/bar/(?!.*\.jar$).+
He 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 means looking for files in "foo / bar /", then do not match if there are zero or more characters followed by ".jar" and then more characters ($ means end of line), then if it is not, match any of the following characters.
Michael La Voie Oct 02 '09 at 22:27 2009-10-02 22:27
source share