import re
rx = r"(a.*?c)?.*g"
s = "abcdefg"
m = re.search(rx, s)
if m:
	print(m.group(0))
	print(m.group(1))
