如何使用自定义的蚂蚁规则的正则表达式pression改变财产propertyfile [英] How to use custom ant rule regexpression to change property in propertyfile
问题描述
在我的Android项目我有我的project.properties文件设置以下属性
In my Android project I have the following property set in my project.properties file
proguard.config=proguard.cfg
和我需要一个自定义宏,会以某种方式设置和取消这个属性。
and I need a custom macro that will somehow set and unset this property.
如何设置取消设置使用微距和普通EX pression这个属性? 两件事情我不清楚是如何将其设置为空的属性值。将会 这只是proguard.config = 或proguard.config =''
How do I set unset this property using macro and regular expression? two things I am not clear on is how to set this to an empty property value. Would that be just proguard.config= or proguard.config=''
什么是宏这样做?
<macrodef name="turn-on-proguard">
<sequential>
<replaceregexp file="./project.properties"
match='proguard.config="(.*)"'
replace='proguard.config=proguard.cfg'
byline="false">
</replaceregexp>
</sequential>
</macrodef>
<macrodef name="turn-off-proguard">
<sequential>
<replaceregexp file="./project.properties"
match='proguard.config="(.*)"'
replace='proguard.config='
byline="false">
</replaceregexp>
</sequential>
</macrodef>
将这项工作?更新。关ProGuard的断什么都不做。
Would this work? Update. turn-proguard-off does nothing.
推荐答案
您的解决方案是非常不清楚我。你为什么不逃点字符?为什么要使用引号和分组在你的正则表达式? 这是工作的脚本:
Your solution is very unclear for me. Why don't you escape the dot character? Why do you use quotation marks and grouping in your regexp? This is working script:
<macrodef name="turnonproguard">
<sequential>
<replaceregexp file="project.properties"
match='proguard\.config=.*'
replace='proguard.config=proguard.cfg'
byline="false"/>
</sequential>
</macrodef>
<macrodef name="turnoffproguard">
<sequential>
<replaceregexp file="project.properties"
match='proguard\.config=.*'
replace='proguard.config='
byline="false"/>
</sequential>
</macrodef>
<target name="on">
<turnonproguard/>
</target>
<target name="off">
<turnoffproguard/>
</target>
这篇关于如何使用自定义的蚂蚁规则的正则表达式pression改变财产propertyfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!