views:

43

answers:

2

Let's assume that we have the next directory structure:

/parentdir/
   /childdir/
      child_file1.txt
      child_file2.jar  
   file1.txt
   file2.txt

so, we get next full file names:

/parentdir/file1.txt
/parentdir/file2.txt
/parentdir/childdir/child_file1.txt
/parentdir/childdir/child_file2.jar

Which regular expression matches all of these files except for the last one with .jar extension?

Little clarification: expression can contain 'parentdir' string and '.jar' string, all other files and directories can have any names and extensions.

+2  A: 

You can use negative assertions : /(?<!\.jar)$/

That would match anything that doesn't end in .jar

Vincent Savard
Unfortunatelly it doesn't work. I use it in mercurials .hgignore file. Maybe, mercurial doesn't support this type of regex.
Roman
It's entirely possible, it's a Perl-compatible regular expression. I don't know mercurial or hgignore, so I can't help more, sorry!
Vincent Savard
It works, it just needs removing of the opening and closing slashes, e.g. "(?<!\.jar)".
Milen A. Radev
+1  A: 

The negative assertion regex is one way to go, but the more common solution for this in mercurial land is to ignore broadly (for example just ignore parentdir/) and then hg add the few exception files you don't wanted ignored.

In svn and cvs you can't add a file that's in your ignore list and if you do future changes aren't tracked, but in mercurial hg add completely overrides ignore, so unless you'll have many new jars showing up in the future, just ignore broadly and add the .jar.

Ry4an
@Ry4an: thanx, didn't know about this hg feature.
Roman