Reputation: 9431
I'm trying to figure out how to replace matching text in my files with contents of file.
Actually I want to inline javascript sources into HTML. But loadfile
doesn't work in replaceregexp
.
<replaceregexp flags="gs">
<regexp pattern="\<!--js--\>(.*?)\<!--/js--\>"/>
<substitution expression='\<script src="min.js"\>\</script\>'/>
<loadfile property="min.js" srcFile="compiled/min.js"/>
</replaceregexp>
Upvotes: 1
Views: 4500
Reputation: 7041
Here's an example of using <replaceregexp>
to replace every <!--js-->***<!--/js-->
with the contents of min.js.
<project name="ant-replaceregexp" default="run" basedir=".">
<target name="run">
<property name="js.pattern"
><![CDATA[[<]!--js--[>](.*?)[<]!--/js--[>]]]></property>
<loadfile property="min.js" srcFile="compiled/min.js"/>
<replaceregexp file="test.html" flags="gs">
<regexp pattern="${js.pattern}"/>
<substitution expression="${min.js}"/>
</replaceregexp>
</target>
</project>
Upvotes: 3