Ant replaceregexp task - match and replace HTML comment block

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 <!--source scripts--><!--end source scripts--> and replaces it with a new script file (in this case min.js), but I have problems with its operation .

This is what I have 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> 
+7
source share
1 answer

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> 
+16
source

All Articles