在Ant replaceregexp任务中匹配多个模式



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

我想将其扩展到所有jsp中<link rel="stylesheet">标记的所有href属性。当我试图再添加一个<regexp>作为时

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

在同一个<replaceregexp>中,我出现错误Only one regular expression is allowed.如何在不使用多个<replaceregexp>块的情况下做到这一点?

您可以在一个表达式中完成此操作:

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

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

最新更新