Ant Tokenizer: Selecting an individual Token
I have the following ant task:
<loadfile property="proj.version" srcfile="build.py">
<filterchain>
<striplinecomments>
<comment value="#"/>
</striplinecomments>
<linecontains>
<contains value="Version" />
</l开发者_如何学Goinecontains>
</filterchain>
</loadfile>
<echo message="${proj.version}" />
And the output is
[echo] config ["Version"] = "v1.0.10-r4.2"
How do I then use a tokenizer to get only v1.0.10-r4.2
, the equivalent of
| cut -d'"' -f4
You could use a containsregex
element within your filterchain
as tokenfilter
.
This should filter any line with "Version"
in it, and return as content the only group captured: 'vx.y.zz....
'
<containsregex
pattern="^.?\"Version\".\"(v[^\"]+?)\"."
replace="\1" />
does not work.
May be <containsregex
pattern='^.?"Version"."(v[^\"]+?)".'
replace="\1" />
could work (with single quotes for the parameter
attribute, allowing for non-escaped double-quotes inside the parameter value)
Actually the OP John Oxley provides a working solution with the double quotes (\"
) replaced by "
:
<containsregex
pattern="^.*?"Version".*"(v[^"]+?)".*"
replace="\1" />
精彩评论