I have assumed the objective is to remove date strings having the format dd-mm-yyyy
when that string is:
- not in the first line of the string
- followed by one or more spaces followed by a time in 24-hour format (e.g.
17:35:16
), followed by zero or more spaces followed by a line terminator (\n
or, for Windows, \r\n
)
- not followed by a blank line
Not that I have made no assumptions about the text that precedes the date strings to be removed, so that the regular expression need not be changed if that text is changed in future.
Under the above assumptions the text matching the following regular expression can be replaced with the contents of capture group 1.
(?<!\A)^(.*) \d{2}-\d{2}-\d{4}(?= +\d{2}:\d{2}:\d{2} *\r?\n(?! *\r?\n))
Demo
The regular expression can be broken down as follows.
(?<!\A) # negative lookbehind asserts current string position
# is not at the beginning of the string
^ # match the beginning of a line
(.*) # match zero or more characters other than line terminators,
# as many as possible, and save to capture group 1
[ ] # match a space
\d{2}-\d{2}-\d{4} # match the string representing the date
(?= # begin a positive lookahead
[ ]+ # match one or more spaces
\d{2}:\d{2}:\d{2} # match the string representing the time
[ ]*\r?\n # match zero or more spaces followed by a line terminator
(?! *\r?\n) # negative lookahead asserts an empty line does not follow
) # end the positive lookahead
In the above I've enclosed most spaces in a character class ([ ]
) merely to make them visible.