multiline variable breaks re.findall output

The example below is a simplified version of the problem I seem to be encountering with re.findall on multiline variables.

Notice the first way works, when it is all on one line...

'''

import re

txt = """Be it every so humble, there's no place like home..."""

x = re.findall("(^Be)(.*)(home...$)", txt)

print(type(x))

for c in x:
    print (x)

'''

but the second way doesn't work when the line is broken...

'''

import re

txt = """Be it every so humble, 
there's no place like home..."""

x = re.findall("(^Be)(.*)(home...$)", txt)

print(type(x))

for c in x:
    print (x)

'''

Is there a way to get it to work on a multiline variable?

Not very experienced with regexing in python, but looking to get more good practice in here. :)

TIA!



Read more here: https://stackoverflow.com/questions/64420763/multiline-variable-breaks-re-findall-output

Content Attribution

This content was originally published by Will at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: