I have an ant property which has value of the type 1.0.0.123
I want to extract the value after the last dot, in this case that would be '123'. Which ant task should i use and how?
If not wanting to use external libs nor scripting, I found in an answer to a similar question the best option (credit him for this answer). Here you'll be using a ReplaceRegex:
<loadresource property="index">
<propertyresource name="build.number"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replaceregex pattern=".*\.)" replace="" />
</tokenfilter>
</filterchain>
</loadresource>
(I have used the same variable names as you in your solution. Of course, this is still missing the increment part of your answer, but that was not in your question.)
This script loads in index
the result of deleting the regex .*\.)
from build.number
, that is, if build.number = 1.0.0.123
then index = 123
.
build.xml:
<project name="ParseBuildNumber" default="parse" basedir=".">
<property name="build.number" value="1.0.0.123"/>
<target name="parse">
<loadresource property="index">
<propertyresource name="build.number"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replaceregex pattern=".*\." replace="" />
</tokenfilter>
</filterchain>
</loadresource>
<echo message="build.number=${build.number}; index=${index}"/>
</target>
</project>
$ ant
Buildfile: /tmp/build.xml
parse:
[echo] build.number=1.0.0.123; index=123
BUILD SUCCESSFUL
Total time: 0 seconds
I suspect the easiest approach may be to use the ant-contrib PropertyRegex task.
Something like this - completely untested:
<propertyregex property="output"
input="input"
regexp=".*([^\.]*)"
select="\1" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With