I'm trying to use python regex on a pattern that has two sets of optional characters that may or may not be there. Below is what I'm trying to accomplish.
h becomes a when h is preceded by o but can also be preceded by a colon (:)
following the o and then maybe followed by f,y,r (f|y|r)
So this rule would be applied to the following patterns.
o:fh -> o:fa
ofh -> ofa
o:h -> o:a
oh -> oa
Below is what I'm trying.
re.sub(ur"o[(:|)][(f|y|r)]h", "o\1\2a", word);
I'm really struggling with the grouping and the two sets of optional characters : and (f|y|r) that may or may not be there. Any help is greatly appreciated. Thanks!

hbecomesathen why ishin the replacement?