Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant replaceregexp task - Match and replace HTML comments block

Tags:

regex

apache

ant

I have the following block that starts and ends with HTML comments:

    <!--source scripts-->
    <script type="text/javascript" src="/assets/js/namespaces.js"></script>
    <script type="text/javascript" src="/assets/js/main.js"></script>
    <script type="text/javascript" src="/assets/js/header.js"></script>
    <script type="text/javascript" src="/assets/js/headerPremiumForm.js"></script>
    <script type="text/javascript" src="/assets/js/bootstrap.js"></script>
    <!--end source scripts-->

I created an ant task that finds everything between the <!--source scripts--><!--end source scripts--> and replaces it with a new script file (in this case min.js), but I have trouble making it work.

This is what I've done so far:

<target name="update-source-with-new-compiled-files">
    <replaceregexp match="\&lt;!--source scripts--\&gt;(.*?)\&lt;!--end source scripts--\&gt;" replace="\&lt;script src='min.js'\&gt;\&lt;/script\&gt;" flags="g">
        <fileset dir="${basedir}/../dist" includes="*"/>
    </replaceregexp>
</target>
like image 888
72lions Avatar asked Nov 04 '11 00:11

72lions


1 Answers

Just add the s flag to your flags :

<replaceregexp match="\&lt;!--source scripts--\&gt;(.*?)\&lt;!--end source scripts--\&gt;" replace="\&lt;script src='min.js'\&gt;\&lt;/script\&gt;" flags="gs">
        <fileset dir="${basedir}/../dist" includes="*"/>
</replaceregexp>
like image 144
FailedDev Avatar answered Nov 10 '22 01:11

FailedDev