1
下面的函数,它由一个模式的出现将字符串分割不工作时,括号内文字跨多行:正则表达式分割多行
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""")
我不知道,如果是正则表达式错误或者如果我错误地使用split
函数中的标志。