开发者

How to make up a regexp that matches all files in the directory except for files with .jar extension?

开发者 https://www.devze.com 2023-01-22 14:12 出处:网络
Let\'s assume that we have the next directory structure: /parentdir/ /ch开发者_StackOverflow中文版ilddir/

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

/parentdir/
   /ch开发者_StackOverflow中文版ilddir/
      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.


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

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消