我在文件中有以下内容
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所以可以使用这些任务.
基于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)
| 归档时间: |
|
| 查看次数: |
10259 次 |
| 最近记录: |