假设我们有一根绳子
string="This is a test code [asdf -wer -a2 asdf] >(ascd asdfas -were)\
test \
(testing test) test >asdf \
test"
我需要得到字符>;和字符串“test”之间的字符串。你知道吗
我试过了
re.findall(r'>[^)](.*)test',string, re.MULTILINE )
不管我得到什么
(ascd asdfas -were)\ test \ (testing test) test >asdf.
但是我需要:
(ascd asdfas -were)\
以及
asdf
我怎样才能得到那两根绳子?你知道吗
关于:
输出:
这种模式中唯一有趣的部分是:
.*?
,其中?
使.*
“ungreedy”变为“ungreedy”,否则将有一个长匹配,而不是两个。你知道吗\btest\b
作为“结束”标识符(参见下面Jan的评论)而不是test
。Where,注意,它可能正在阅读^{} ,因为我认为这才是你真正想要的。} 让锚(
DOTALL
让.
字符包含换行符,而^{^
,$
)匹配行的开始和结束,而不是整个字符串。考虑到您不使用锚定,我认为DOTALL
更合适。你知道吗相关问题 更多 >
编程相关推荐