<p>I need to increment a number in a source file from an Ant build script. I can use the <code><a href="http://ant.apache.org/manual/Tasks/replaceregexp.html" rel="nofollow noreferrer">ReplaceRegExp</a></code> task to find the number I want to increment, but how do I then increment that number within the <code>replace</code> attribute?</p>

<p>Heres what I've got so far:</p>

<pre><code>&lt;replaceregexp file="${basedir}/src/path/to/MyFile.java"
    match="MY_PROPERTY = ([0-9]{1,});"
    replace="MY_PROPERTY = \1;"/&gt;
</code></pre>

<p>In the replace attribute, how would I do </p>

<pre><code>replace="MY_PROPERTY = (\1 + 1);"
</code></pre>

<p>I can't use the <code>buildnumber</code> task to store the value in a file since I'm already using that within the same build target. Is there another ant task that will allow me to increment a property?</p>

You can use something like:
```
<propertyfile file="${version-file}">
 <entry key="revision" type="string" operation="=" value="${revision}" />
 <entry key="build" type="int" operation="+" value="1" />
```
so the ant task is propertyfile.