title: ant replaceregexp, matching with variable/property
body: <p>This should be a common problem but I can't figure out how to do it, hoping for some guidance here. </p>
  
  <p><strong>The problem:</strong></p>
  
  <p>I need to replace some, but not all application versions in a set of XML configuration files (weblogic config.xml files) using ant (ant-contrib is also ok to use).</p>
  
  <p>I have a list of applications that should have new version set, and what version they should have and I have the configuration files where I need to to the replace. </p>
  
  <p><strong>The path I took so far:</strong></p>
  
  <p>I created a macro that takes three arguments; application name, application version and config file. </p>
  
  <p>This will be invoked from a loop.</p>
  
  <p>Here is what I have right now:</p>
  
  <pre><code>&lt;macrodef name="update-template-config-file"&gt;
    &lt;attribute name="application-name" /&gt;
    &lt;attribute name="application-version" /&gt;
    &lt;attribute name="config-file-name" /&gt;
  
    &lt;sequential&gt;
  
      &lt;local name="match-string"/&gt;
      &lt;local name="replace-string"/&gt;
      &lt;property name="match-string" value="@{application-name}#[0-9](\.[0-9])*"/&gt;
      &lt;property name="replace-string" value="@{application-name}#@{application-version}"/&gt;
  
      &lt;echo&gt;match ${match-string} replace: ${replace-string} in @{config-file-name}&lt;/echo&gt;
  
      &lt;replaceregexp file="@{config-file-name}"
        match="${match-string}"
        replace="${replace-string}"
        byline="true"/&gt;
    &lt;/sequential&gt;
  
  &lt;/macrodef&gt;
  </code></pre>
  
  <p>So the issue with this is that the match part of replaceregexp is interpretated as a regular expression (correctly), and I'm wondering if there is a way to use value of 'match-string' property rather than the name of it. </p>
  
  <p><strong>Workaround:</strong></p>
  
  <p>From ant script, create a new ant script by echoing replacement instructions per loop, then invoke the created ant file to execute the replacements.</p>
  
  <p><strong>For completeness, target where macro is called</strong></p>
  
  <pre><code>&lt;target name="update-template-config-files"&gt;
    &lt;for param="config-file"&gt;
       &lt;path&gt;
         &lt;fileset dir="${RP_CONTENT_ROOT_DIR}/domain_templates" includes="**/config.xml"/&gt;
       &lt;/path&gt;
      &lt;sequential&gt;
        &lt;for param="application-file"&gt;
          &lt;path&gt;
            &lt;fileset dir="${STAGE_ROOT}/applications" includes="*.*"/&gt;
          &lt;/path&gt;
          &lt;sequential&gt;
            &lt;local name="filename"/&gt;
            &lt;basename property="filename" file="@{application-file}"/&gt;
            &lt;update-template-config-file application-name="${filename}" application-version="5.1.0.3.0" config-file-name="@{config-file}" /&gt;
          &lt;/sequential&gt;
        &lt;/for&gt;
      &lt;/sequential&gt;
    &lt;/for&gt;
  &lt;/target&gt;
  </code></pre>