ant replaceregexp xml换行符

时间:2016-08-25 12:48:29

标签: regex ant newline

我正在尝试使用ANT replaceregexp任务将xml元素值从“true”更改为“false”,但是在新行匹配时遇到困难。有问题的XML节点的相关部分:

<validationRules>
    <fullName>CAReversaApprovallLockdown</fullName>
    <active>true</active>

在我的文本编辑器(sublime)中,我能够使用以下正则表达式来查找/替换,但我无法弄清楚如何在ANT replaceregexp中复制它:

/fullname>\n        <active>true

我无法找出正确的语法来匹配换行符和后续行间距的组合。换行符之后的间距始终相同,如果这样可以使事情变得更容易。

https://ant.apache.org/manual/Tasks/replaceregexp.html我尝试了各种^和$的组合,带有m标志,\ s +用于空格等,但只是无法击中正确的组合....任何想法?

我目前的进展如下,但遗憾的是没有运气......

<target name="deactivate_val_rules">
    <echo message="deactivating validation rules..." />
    <replaceregexp match="/fullname&gt;\r\n\s+&lt;active&gt;true" flags="gim" byline="false">
        <substitution expression="/fullname&gt;\r\n        &lt;active&gt;false"/>
        <fileset dir="src\objects" includes="Claim_Approvals__c.object"/>
    </replaceregexp>
</target>

2 个答案:

答案 0 :(得分:0)

要使用replaceregexp,您需要定义要更改的值作为参考。

例如:

<validationRules>
    <fullName>CAReversaApprovallLockdown</fullName>
    <active>true</active>

蚂蚁:

<target name = "deactivate_val_rules">
    <echo message="deactivating validation rules..." />
    <replaceregexp file="${FILE_LOACTION}/FILE_NAME.FILE_EXT" match="true" replace="false" />   
</target>

答案 1 :(得分:0)

得到它 - 以下给出了正确的结果:

<target name="deactivate_val_rules">
    <echo message="deactivating workflows..." />
    <replaceregexp match="/fullname&gt;\r\n\s+&lt;active&gt;true" flags="gis" byline="false">
        <substitution expression="/fullname&gt;${line.separator}        &lt;active&gt;false"/>
        <fileset dir="src\objects" includes="Claim_Approvals__c.object"/>
    </replaceregexp>
</target>

通过diff查看的输出是:

  -  <fullName>the_name</fullName>
  -  <active>true</active>
  +  <fullName>the_name</fullname>
  +  <active>false</active>