The following function which splits a string by the occurrence of a pattern doesn't work when the text inside brackets spans multiple lines:
import re
def header(text):
authors = [i.strip() for i in re.split(r'\\and|\\thanks\{.*?\}', text, flags=re.M)]
names = filter(None,authors)
return '{} and {}'.format(', '.join(names[:-1]), names[-1])
print header(r"""John Bar \and Tom Foo\thanks{Testing if this works with
multiple lines} \and Sam Baz""")
I don't know if the regex is wrong or if I'm using incorrectly the flag in the split
function.