根据文件中的正则表达式设置Ant属性

Mat*_*son 4 regex ant

我在文件中有以下内容

version: [0,1,0]
Run Code Online (Sandbox Code Playgroud)

我想将Ant属性设置为字符串值0.1.0.

正则表达式是

version:[[:space:]]\[([[:digit:]]),([[:digit:]]),([[:digit:]])\]
Run Code Online (Sandbox Code Playgroud)

然后我需要将属性设置为

\1.\2.\3
Run Code Online (Sandbox Code Playgroud)

要得到

0.1.0
Run Code Online (Sandbox Code Playgroud)

我无法一起锻炼如何使用Ant任务来完成这项工作.

我有Ant-contrib所以可以使用这些任务.

com*_*oro 5

基于matt的第二个解决方案,这适用于任何(文本)文件,一行或不一行.它没有apache-contrib依赖项.

<loadfile property="version" srcfile="version.txt">
  <filterchain>
    <linecontainsregexp>
      <regexp pattern="version:[ \t]\[([0-9]),([0-9]),([0-9])\]"/>
    </linecontainsregexp>
    <replaceregex pattern="version:[ \t]\[([0-9]),([0-9]),([0-9])\]" replace="\1.\2.\3" />
  </filterchain>
</loadfile>  
Run Code Online (Sandbox Code Playgroud)