Replacing part of a string in Powershell with regular expressions
<p>I have a problem:</p>

<p>I have an XML file which contains:</p>

<pre><code>&lt;colortable&gt;
&lt;color id="1" type="transparent"/&gt;
&lt;color id="2"/&gt;
&lt;color id="3" values="1.0"/&gt;
&lt;color id="4" type="rgb" values="0.0,0.0,0.0"/&gt;
&lt;color id="5" type="rgb" values="1.0,1.0,1.0"/&gt;
&lt;/colortable&gt;
&lt;imagetable&gt;
&lt;imagedata id="1" source="E:\xml2pdf_universal_physical_layer\tmp\dbres22C79BB2A484491458226919210\r.437248.1395746975.csfolha1v2SemMensagem_Tim.jpg"&gt;
&lt;/imagedata&gt;
&lt;imagedata id="2" source="E:\xml2pdf_universal_physical_layer\tmp\dbres22C79BB2A484491458226919210\r.42189.1400584131.csfolha2v2fiscal_Tim.jpg"&gt;
&lt;/imagedata&gt;
&lt;imagedata id="3" source="E:\xml2pdf_universal_physical_layer\tmp\dbres22C79BB2A484491458226919210\r.488328.1422006304.DT1_Image6_T.jpg"&gt;
&lt;/imagedata&gt;
&lt;imagedata id="4" source="E:\xml2pdf_universal_physical_layer\tmp\dbres22C79BB2A484491458226919210\r.1262464.1427173896.csfolha3v2fiscal_Tim.jpg"&gt;
&lt;/imagedata&gt;
&lt;imagedata id="5" source="E:\xml2pdf_universal_physical_layer\tmp\dbres22C79BB2A484491458226919210\r.54571.1400584131.csfolha0v2fiscal_Tim.jpg"&gt;
&lt;/imagedata&gt;
&lt;/imagetable&gt;
</code></pre>

<p>I want change the path from the one above to <code>C:\images\</code></p>

<p>I'm trying to use this Powershell code:</p>

<pre><code>while ($line = [Console]::In.ReadLine()) 
{ 
  switch -wildcard ($line) 
  { 
   '&lt;imagedata*' {$line -replace '[A-Z]{1}:.+[r][.]([0-9]+[.]){2}', 'c:\images\'} 
   default {$line}
  }
}
</code></pre>

<p>I want this to, for every string starting with <code>&lt;imagedata</code>, find the path (matching a regexp) and replace it with a new path.</p>

<p>This isn't working. How can I fix it?</p>