March 14th, 2013, 01:04 PM
FreePascal regexp_replace equivalent?
Is there an easy way to do a RegExp replace in FreePascal/Lazarus?
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.
What I'm trying to acheive is as follows.
- I have an XML file loaded into a SynEdit component.
- The XML file has a decalaration at the start <? .... ?>
- The DTD is held in a seperate file.
- I don't want to combine the two in one file, but I do wantto validate the XML as it is being editted.
- 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.
So essentially I have:
And I want to do a RegExp type search and replace for 'Line1' replaceing with 'Line1\nLineExtra' to give me:
For example in PHP I would use:
Or is there an easier way without using regular expressions - I don't want to assume that the <? ... ?> declaration is always there in the corcet position on Line 1 though - just to complicate things.