stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx"
stringB = "FoundA"
stringC = "FoundB"
如何在python中執行正則表達式以返回aaaaaaaaaaaaa?
請幫忙。 先謝謝。
stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx"
stringB = "FoundA"
stringC = "FoundB"
如何在python中執行正則表達式以返回aaaaaaaaaaaaa?
請幫忙。 先謝謝。
>>>
>>> stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx"
>>> stringB = "FoundA"
>>> stringC = "FoundB"
>>>
>>> import re
>>> re.search(re.escape(stringB)+"(.*?)"+re.escape(stringC),stringA).group(1)
'aaaaaaaaaaaaaa'
>>>
**失敗**沒有使用re.escape()** – 2010-04-30 05:14:30
我添加了@John。 – YOU 2010-04-30 05:19:45
re.search(re.escape(stringB) + "(.*?)" + re.escape(stringC), stringA).group(1)
如果你有'stringA = 「xxxxxxFoundAaaaaaFoundAaaaaFoundBaaaaaFoundBxxxxxxx」'會發生什麼??? – nosklo 2010-04-30 17:50:58