Shoreki
Shoreki

Reputation: 1097

Matching multiple pattern in Ant replaceregexp task

I have a task in my Ant build script for adding a parameter to the src attribute to all <script> tags in jsp files.

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

I want to extend this to all href attributes of <link rel="stylesheet"> tags in all jsps. When I tried to add one more <regexp> as

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

in the same <replaceregexp>, I am getting error Only one regular expression is allowed. How can I do this without using multiple <replaceregexp> blocks?

Upvotes: 0

Views: 3988

Answers (1)

greg-449
greg-449

Reputation: 111142

You can do this in one expression:

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

Which matches js or css in a capturing group and uses the captured value in the substitution.

Upvotes: 2

Related Questions