【问题标题】:Matching multiple pattern in Ant replaceregexp task在 Ant replaceregexp 任务中匹配多个模式
【发布时间】:2013-08-29 22:42:00
【问题描述】:

我在我的 Ant 构建脚本中有一个任务,用于将参数添加到 jsp 文件中的所有 <script> 标记的 src 属性。

       <replaceregexp flags="gi">               
            <fileset dir="${build.web.dir}/WEB-INF/jsp" >   
                <filename name="*.jsp"/>
            </fileset>                  
            <regexp pattern=".js&quot;>"/>
            <substitution expression=".js?param=${pValue}&quot;>"/>         
        </replaceregexp>

我想将此扩展到所有 jsps 中 &lt;link rel="stylesheet"&gt; 标记的所有 href 属性。当我尝试再添加一个 &lt;regexp&gt; 作为

<regexp pattern=".css&quot;>"/>
    <substitution expression=".css?param=${pValue}&quot;>"/>

在同一个&lt;replaceregexp&gt;,我收到错误 Only one regular expression is allowed. 如何在不使用多个 &lt;replaceregexp&gt; 块的情况下做到这一点?

【问题讨论】:

    标签: java regex eclipse ant build


    【解决方案1】:

    您可以在一个表达式中做到这一点:

      <regexp pattern=".(js|css)&quot;>"/>
        <substitution expression=".\1?param=${pValue}&quot;>"/>         
    

    与捕获组中的 js 或 css 匹配,并在替换中使用捕获的值。

    【讨论】:

    • 顺便说一句,那是领先的。在旨在仅匹配“。”的模式中特点?如果是这样,则需要对其进行转义。
    猜你喜欢
    • 2011-12-21
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 2012-05-15
    相关资源
    最近更新 更多