例如:
string = "abcdefghi"
separated = "abc" + x + "ghi"
x = ???
我想使用任何字符串查找 x。
x=re.search('(?<=abc).*(?=ghi)','abcdefghi').group(0)
print(x)
输出
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
re.search
文档在这里。
AMatch Object
由 返回re.search
。一个group(0)
上调用将返回全场比赛。Match Object
可在此处找到详细信息。
注:
正则表达式是剧烈而将匹配/回报defghixyz
在abcdefghixyzghi
。在这里
查看演示。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句