Search code examples
regexjedit

Find from last blank line to string using regex


I need to do a search in jEdit for a string starting with the end of the last empty line up to another string:

blah
blah 
blah 
blah
blah 
empty line
empty line
empty line *start here*
blah 
blah
blah blah blah
blah
blah
blah ------ Running ------

The idea is to do a search and replace to remove everything (i've bolded) before the string ------ Running ------ but not the lines or strings before that last line.

Can someone suggest the proper regex to find from end of last line up to the beginning of the string ------ Running ------ ?

Thanks!


Solution

  • Use the below regex and then remove the matched string with an empty string.

    (?s)(?<=\n)(?:(?!\n\n).)*\n(?=[^\n]+------ Running ------)
    

    Java regex would be,

    (?s)(?<=\\n)(?:(?!\\n\\n).)*\\n(?=[^\\n]+------ Running ------)
    

    DEMO