我有
stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx"
stringB = "FoundA"
stringC = "FoundB"
如何在python中执行正则表达式以返回aaaaaaaaaaaaaa?
请帮忙。 提前谢谢。
答案 0 :(得分:14)
>>>
>>> stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx"
>>> stringB = "FoundA"
>>> stringC = "FoundB"
>>>
>>> import re
>>> re.search(re.escape(stringB)+"(.*?)"+re.escape(stringC),stringA).group(1)
'aaaaaaaaaaaaaa'
>>>
答案 1 :(得分:4)
re.search(re.escape(stringB) + "(.*?)" + re.escape(stringC), stringA).group(1)