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!
Find lowest matching string and insert line below
- DigitalVolcano
- Site Admin
- Posts: 1863
- Joined: Thu Jun 09, 2011 10:04 am
Re: Find lowest matching string and insert line below
A Regular Expression using Negative Lookaheads should work. This assumes your file has CR/LF line endings (\r\n)
RegEx:
Replace:
For your example, this produces:
RegEx:
Code: Select all
PAR(?!.*PAR)(.*?)(\r\n)
Code: Select all
$0NEW TEXT\r\n
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
Thanks,
This works excellent for what I want to change!
Regards!
This works excellent for what I want to change!

Regards!
Re: Find lowest matching string and insert line below
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!
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!