简体   繁体   中英

Python match and return string in between

I have following code

stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx"
stringB = "FoundA"
stringC = "FoundB"

How do I do a regular expression in python in order to return aaaaaaaaaaaaaa ?

>>>
>>> stringA = "xxxxxxFoundAaaaaaaaaaaaaaaFoundBxxxxxxx"
>>> stringB = "FoundA"
>>> stringC = "FoundB"
>>>
>>> import re
>>> re.search(re.escape(stringB)+"(.*?)"+re.escape(stringC),stringA).group(1)
'aaaaaaaaaaaaaa'
>>>
re.search(re.escape(stringB) + "(.*?)" + re.escape(stringC), stringA).group(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM