2

I'm trying to write a regular expression for an Ant task that excludes files in a directory that end with a certain character sequence. For example, I have the following three files:

file01.js
file02.js
file02-copy.js

I want an expression that finds the first two files and ignores the one with "-copy" on the end. I've tried using <include>'s and <excludes>'s like so:

<fileset dir="." includes="js/">
    <include name="*.js"/>
    <exclude name="*copy*"/>
</fileset>

but obviously because its a JS file, its still included. So I'm trying to use a regular expression to match the files (if anyone has another suggestion please do suggest):

<fileset dir="." includes="js/">
    <containsregexp expression="...">
</fileset>

And here lies my problem. I can't find a regEx that does this match for me. I've tried a few things like (\w*)(!-copy).js but this does nothing. If anyone could help me out I'd be very grateful.

Did I mention that I hate trying to write regEx's?

MeanwhileInHell
  • 6,780
  • 17
  • 57
  • 106
  • Just so we're not solving the wrong problem, could you outline the file/directory structure for your files? Are your file*.js files in the "." directory or in the "js/" directory? – claesv Mar 29 '12 at 09:41

2 Answers2

3

I'd skip the include directives, and only add exclude directives for everything that's explicitly excluded. Other files will then be implicitly included.

I don't know what your file structure looks like, so I might be wrong about this one, but maybe this would do the trick:

<fileset dir="js" excludes="*copy*" />
claesv
  • 2,075
  • 13
  • 28
0

Try match for (?m)^(?=.js)((?!copy.js).)$

More info can be found in below link. Excellent post.

Regular expression to match a line that doesn't contain a word?

Community
  • 1
  • 1
Unni Kris
  • 3,081
  • 4
  • 35
  • 57