Just replace ? with * to capture all characters.
?
*
import re string = ":example1:q=dfgghp-yoirjl78/-" print(string) x = re.sub(r':q=.*','', string) print(x)