Q:

Regular Expression Delete Everything Before Line

I am trying to use a regex to delete everything before a certain line in a multi-line string. Is there a regex expression that captures everything before (and including) an expression?
import re

sample = '''
This is content I need to delete
I do not need any of this.

===

Text I need 
Is here'''

content = re.sub(r'\n===', "", sample)

print(content)

A:

If you want to be left with just
Text I need
Is here

(so without any more newlines after the ===) you can use
content = re.sub(r'(.|\n)*===\n*', "", sample)

The (.|\n)* will get rid of all the text and newlines up to the === and the \n* will delete the following newlines. You can also leave this last part out if you want to keep the newlines after ===. So
content = re.sub(r'(.|\n)*===', "", sample)

will result in
             // newline 
             // newline
Text I need 
Is here

There will be two newlines left (one directly after the === and the second one for the empty line). If you just want one newline before Text I need... then use:
r'(.|\n)*===\n'

