SED

https://www.regextester.com/1946

G8 = P(G1,G3)
G9 = P(G3,G4)