使用python查找字符串的一部分?

使用python查找字符串的一部分?,python,Python,例如: string = "abcdefghi" separated = "abc" + x + "ghi" x = ??? 我想用任意字符串找到x x=re.search('(?<=abc).*(?=ghi)','abcdefghi').group(0) print(x) 解释 正则表达式 (?x=re.search('(?@bulbus-你真的认为发布一个正则表达式,作为一个没有解释的评论,对提出这样一个问题的人有帮助吗?或者一些可怜的迷失的灵魂,不知道通过谷歌到达这里的re模块s

例如:

string = "abcdefghi"
separated = "abc" + x + "ghi"
x = ???
我想用任意字符串找到x

x=re.search('(?<=abc).*(?=ghi)','abcdefghi').group(0)
print(x)
解释 正则表达式


(?
x=re.search('(?@bulbus-你真的认为发布一个正则表达式,作为一个没有解释的评论,对提出这样一个问题的人有帮助吗?或者一些可怜的迷失的灵魂,不知道通过谷歌到达这里的
re
模块search@DavidMakogon道歉!作为答案发布。想测试用户是否觉得它有用。
def
(?<=abc)  #Positive look behind. Start match after abc
.*        #Collect everything that matches the look behind and look ahead conditions
(?=ghi)   #Positive look ahead. Match only chars that come before ghi