【发布时间】:2021-12-11 01:17:54
【问题描述】:
下面是我的多行字符串。
sample='''
blah
blah
blah
blah
text.get(
'hi'
'you're
'welcome'
)
text.get(
'hi'
'i'm
'here'
> )
blah
blah
blah
我想根据符号>进行匹配,得到括号内的相关文字
text.get(
'hi'
'i'm
'here'
> )
我试过这段代码
text(.+)\((.*?)>(.*?)\) 它匹配 text.get 的两个实例。有人可以帮忙吗
【问题讨论】:
-
您需要使用
re.DOTALL标志来允许.*跨行匹配。 -
您希望返回包含
"'hi'"、"'i'm"、"'here'"和"> "这四行的字符串吗?顺便说一句,我认为您的意思是括号("("和">"),而不是括号("["和"]")。