编写一个正则表达式来获取字符,直到被搜索到为止。在这里,直到#
我需要提取
import re
text = '''text1
text2
text3
#text4
text5'''
print(re.search('(?s)\A.*?(\#)',text))
我的出场
<re.Match object; span=(0,19),match='text1\ntext2\ntext3\n#'>
预期
<re.Match object; span=(0,match='text1\ntext2\ntext3'>