Page 1 of 1

Find lowest matching string and insert line below

Posted: Fri Sep 14, 2018 3:41 pm
by XJAC
Hi,

I'm searching for a way/ or how can I build an expression to do something like this.
The file contains numerious lines with a specific string in it. Here I used 'PAR' This string is at the beginning of the line and has other data after it.
Below the last line found with PAR in it, I want to insert a new line with a specific, fixed text

PAR length= 300
PAR width= 600
PAR height= 18
PAR type= 3
Here I want to insert a new line with specific text.

Thanks in advance for everyone who can help me a bit further!

Re: Find lowest matching string and insert line below

Posted: Mon Sep 17, 2018 11:11 am
by DigitalVolcano
A Regular Expression using Negative Lookaheads should work. This assumes your file has CR/LF line endings (\r\n)

RegEx:

Code: Select all

PAR(?!.*PAR)(.*?)(\r\n)
Replace:

Code: Select all

$0NEW TEXT\r\n
For your example, this produces:

Code: Select all

PAR length= 300
PAR width= 600
PAR height= 18
PAR type= 3
NEW TEXT

Re: Find lowest matching string and insert line below

Posted: Wed Sep 19, 2018 12:38 pm
by XJAC
Thanks,

This works excellent for what I want to change! :D


Regards!

Re: Find lowest matching string and insert line below

Posted: Mon Sep 24, 2018 7:57 am
by XJAC
Hi,

I have another question concerning this case.

I have also files where it's like this

PAR ....
PAR ....
PAR ....
D ...

Is it possible when D occurs, the new line is inserted below the D, and if D is not inside the program, it is inserted after PAR?

Thanks!