import re with open('tmp_home_current4.html', 'r') as f: content = f.read() # The text to add: Kevin McKeand Coaching, centered, #316263, 54px, bold. new_heading = """

Kevin McKeand Coaching

\n\n""" target_regex = r'(\n

Enabling Others To Achieve Their Potential

\n)' new_content = re.sub(target_regex, new_heading + r'\1', content) if content == new_content: print("Warning: Content was not updated. Regex might have failed.") else: print("Content successfully updated.") with open('tmp_home_updated.html', 'w') as f: f.write(new_content)