Find a string with RegEx and insert one line before

A place to try and solve your RegEx problems.
Post Reply
zug7
Posts: 1
Joined: Thu Sep 09, 2021 6:51 am

Find a string with RegEx and insert one line before

Post by zug7 »

I have the following kind of text:

int ADR_USD(0);
if date >= ELDate (10,12,2012) THEN BEGIN

if date >= ELDate(10,12,2012) and date < ELDate(08,12,2013) then begin


I need to insert/change this as follows:

int ADR_USD(0),
int PT_pointValue(0);

if date >= ELDate (10,12,2012) THEN BEGIN

if date >= ELDate(10,12,2012) and date < ELDate(08,12,2013) then begin

The line "int ADR_USD(0);" will always end with an ";", but the rest might be different. The ";" needs to change to ",".
The line "int PT_pointValue(0);" is new and should be inserted. Inside one text file there should be only be one line inserted.
The line "if date >= ELDate (10,12,2012) THEN BEGIN" will be basically the same with different values inside the brackets. No change to this line.
The line " if date >= ELDate(10,12,2012) and date < ELDate(08,12,2013) then begin" should not be used to insert the line "int PT_pointValue(0);"

I can see that without RegEx I could easily do this. But as I need RegEx to identify the correct position I don't see a function like "insert before".

Is there a way to do this with RegEx?

Thank you very much for you help in advance,
Thomas
Post Reply