【问题标题】:ant ReplaceRegExp to replace string with double quotesant ReplaceRegExp 用双引号替换字符串
【发布时间】:2015-12-02 14:56:40
【问题描述】:

使用 ANT 我正在尝试使用 ANT replaceregexp 任务查找/替换带有空格和双引号的字符串。

xml中的实际标签

    <ser:debug enabled="false">

以下都失败了。

"<replaceregexp file="filepath" match="debug enabled="false"" replace="debug enabled="true"" byline="true" />"

"<replaceregexp file="filepath" match="debug\ enabled\=\"false\"" replace="debug\ enabled\=\"true\"" byline="true" />"

我收到此错误:

元素类型“replaceregexp”必须后跟属性规范,“>”或“/>”

但是,对于不同的标签,这个工作正常,没有任何问题......因为没有这样的特殊字符。

<replaceregexp file="filepath" match="sql-debug-mode>true" replace="sql-debug-mode>false" byline="true" />

【问题讨论】:

  • 用 xml char 实体尝试过这种方式(不确定我做的是否正确)&lt;replaceregexp file="filepath" match="debug enabled=&amp;quotfalse&amp;quot" replace="debug enabled=&amp;quottrue&amp;quot" byline="true" /&gt; 但出现此错误 对实体“quotfalse”的引用必须以 ';' 结尾分隔符。
  • 您错过了实体上的分号:&amp;quot;
  • 非常感谢,也试过用 ' 单引号括起来……这行得通

标签: java .net regex ant build-automation


【解决方案1】:

也尝试过用 ' 单引号包围...这很有效 – enthuguy

【讨论】:

    【解决方案2】:

    我需要将 dir="EAR" 替换为 "${stage.prj.dir}EAR"

    这对我有用

    <replaceregexp file="${stage.prj.dir}/LMS_HOME/EAR/ExtLib/jar_replace.xml"
                   match="&quot;EAR&quot;"
                   replace="&quot;${stage.prj.dir}EAR&quot;"
                   byline="true"/>
    

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多