I was working with some logs in which there are several separators for each information field, e.g.:
********** Field #1 **********
Content inside Field #1
More content
********** Field #2 **********
Content inside Field #2
More content
...
********** The last field will always remain unchanged **********
Unchanged content from last field
Periodically, I have to delete all the content from the respective fields and manually provide the new data that is going to occupy that space. The problem is that the logs are way too long to select and delete all of that content by hand, so I wrote a RegEx in Notepad
find/replace to detect the end of a separator *
and subsequent lines with \r\n
until it bumps into another *
.
Here follows my expression:
(?<=\*)([^\*] \r\n)(?=\*)
How it works:
- First group: captures the last
*
from a group of stars/asterisks separator; - Second group: captures everything that is not an asterisk or text inside the separators and ends with line break (at least I believe this is the correct interpretation);
- Third group: captures the beginning of a left separator
*
.
As you may have read in the log example, the last field must stay unchanged, no matter what. So I am struggling to match the exact place after the last field. I tried putting some unique reference from the last field's content inside the negated \*
matching list in group 2,but no success.
Currently, the solution I wrote works well with all fields, but I wanted to make it regarding the condition that the last field must stay the same and be able to Replace All
without changing last field. Is there any way we can work with the existing solution and improve it? If not, is there another different solution for this case?
Thank you so much in advance for any help.