u = 'stringandstring'
b = "network:"
e = "yeser;"
def haystack(b,e,u):
i = re.search('%s(.*)%s', u)
r = i.group(1)
return r
或
.....
def haystack(b,e,u):
i = re.search('b(.*)e', u)
.....
如何正确地在函数中获取这些变量?
答案 0 :(得分:1)
我想你可以尝试连接(str1 + str2)
def haystack(b,e,u):
i = re.search(b+'(.*)'+e, u)
if i: #check if there is any result
return i.group(1) #return match
#now try to call it
print haystack("this","str","this is str") #this should output ' is '
print haystack("no","no", "this is str") #this should not print anything
到目前为止,这对我来说非常合适