有没有一种优雅的单行方法来查找包含 7 的数字,除非它只是 7?
if re.search(r'(\d+)?(7)(\d+)', line):
print "Found 7 inside or beginning of a number", match.group()
else:
if re.search(r'(\d+)(7)(\d+)?', line):
print "Found 7 in the end of a number", match.group()