【问题标题】:ant replaceregexp xml newlineant replaceregexp xml 换行符
【发布时间】:2016-08-25 12:48:29
【问题描述】:

我正在尝试使用 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>

【问题讨论】:

    标签: regex ant newline


    【解决方案1】:

    知道了 - 以下给出了正确的结果:

    <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>
    

    【讨论】:

      【解决方案2】:

      要使用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>
      

      【讨论】:

      • 所以您需要扫描所有嵌套文件目录以查找 元素并替换它的值?
      • 我不能简单地将 true 替换为 false,因为还有其他具有 元素的节点 - 文件中最小的唯一值是带有 的 元素换行
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      相关资源
      最近更新 更多