My goal is to find the piece of text between search_term_start and search_term_end. The problem I'm having is that I can only accomplish this if I use a string without '\n' characters. The code below raises an AttributeError.
import re
logs = 'cut-this-out \n\n givemethisstring \n\n and-this-out-too'
search_term_start = '''cut-this-out'''
search_term_end = '''and-this-out-too'''
total_pages = re.search(search_term_start + '(.*)' + search_term_end, logs)
print(total_pages.group(1))
If I remove the '\n' characters from logs, the program runs how I intend it to:
import re
logs = 'cut-this-out givemethisstring and-this-out-too'
search_term_start = '''cut-this-out'''
search_term_end = '''and-this-out-too'''
total_pages = re.search(search_term_start + '(.*)' + search_term_end, logs)
print(total_pages.group(1))
I can't seem to search for substrings in a string if it has '\n' characters. How can I retrieve this substring and save it without removing the '\n's from the original string?