title: freepascal regexp replace
body: <p>Is there an easy way to do a RegExp replace in FreePascal/Lazarus?</p>
  
  <p>Hunting around I can see that I can do a match fairly easily, but I'm struggling to find functions to do a search and replace.</p>
  
  <p>What I'm trying to acheive is as follows.</p>
  
  <ul>
  <li>I have an XML file loaded into a SynEdit component.</li>
  <li>The XML file has a decalaration at the start </li>
  <li>The DTD is held in a seperate file.</li>
  <li>I don't want to combine the two in one file, but I do wantto validate the XML as it is being editted.</li>
  <li>I'm reading the XML into a string variable and I want to insert the DTD between the  and the XML content in a temporary string variable (to create a compliant XML with self contained DTD) that can be parsed and validated.</li>
  </ul>
  
  <p>So essentially I have:</p>
  
  <pre><code>&lt;?Line1?&gt;
  Line2
  Line3
  </code></pre>
  
  <p>And I want to do a RegExp type search and replace for '&lt;?Line1?>' replaceing with '&lt;?Line1?>\n&lt;![DTD\nINFO WOULD\nGO HERE\n!]' to give me:</p>
  
  <pre><code>&lt;?Line1?&gt;
  &lt;![DTD
  INFO WOULD
  GO HERE
  !]
  Line2
  Line3
  </code></pre>
  
  <p>For example in PHP I would use:</p>
  
  <pre><code>preg_replace('/(&lt;\?.*\?&gt;)/im','$1
  &lt;![DTD
  INFO WOULD
  GO HERE
  !]',$sourcestring);
  </code></pre>
  
  <p>But there doesn't seem to be an equivalent set of regexp functions for FreePascal / Lazarus - just a simple/basic RegExp match function.</p>
  
  <p>Or is there an easier way without using regular expressions - I don't want to assume that the  declaration is always there in the correct position on Line 1 though - just to complicate things.</p>
  
  <p>Thanks,</p>
  
  <p>FM</p>