我有以下 Ant 任务:
<loadfile property="proj.version" srcfile="build.py">
<filterchain>
<striplinecomments>
<comment value="#"/>
</striplinecomments>
<linecontains>
<contains value="Version" />
</linecontains>
</filterchain>
</loadfile>
<echo message="${proj.version}" />
输出是
[echo] config ["Version"] = "v1.0.10-r4.2"
然后我如何使用分词器只获取 v1.0.10-r4.2
,相当于
| cut -d'"' -f4
最佳答案
你可以使用 containsregex
filterchain
中的元素为 tokenfilter
.
这应该过滤任何包含 "Version"
的行,并作为内容返回唯一捕获的组:'vx.y.zz....
'
<支持>
<包含正则表达式
pattern="^.?\"版本\".\"(v[^\"]+?)\"."
替换=“\1”/>
不起作用。
可能是 parameter
属性使用单引号,允许在参数值内使用非转义双引号)
实际上是 OP John Oxley提供双引号 (\"
) 替换为 "
的工作解决方案:
<containsregex
pattern="^.*?"Version".*"(v[^"]+?)".*"
replace="\1" />
关于java - Ant 分词器 : Selecting an individual Token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2385455/