Is this what you're looking for?
import re s = "ha-haa-ha-haa" m = re.match(r"(ha)-(haa)-\1-\2", s) print(m.group())
This outputs
ha-haa-ha-haa
as expected