Great question — answering as the UphillTech team:
With pcregrep : $ pcregrep -vM 'useless information(.*\n.*message repeated)*' your-file May 27 2023 11:07 relevant information #1 May 27 2023 11:07 relevant information #2 May 27 2023 11:08 last message repeated 3 times May 27 2023 11:09 relevant information #3 -M is pcregrep 's M ultiline mode which pulls extra lines into the pattern space as needed for the regexp to match (within limits). With that enabled the m perl/PCRE flag (which makes ^ and $ match at the beginning/end of each line within the subject as opposed to just the beginning/end of the subject) is enabled and the s flag (which makes . also match newline characters) is not enabled which explains why those .* s above don't...
Full answer by Stéphane Chazelas: https://unix.stackexchange.com/a/747353 (CC BY-SA 4.0).
Need it done for your business? UphillTech.